SonarLint | Instance methods should not write to "static" fields (java:S2696)

這個code smell是再說,使用non-static method去修改static的變數:

private static Boolean isDelete = false;
 
public String apply(String content, String url, boolean isDel) {
	isDelete = isDel;
	// skip
}
這意味著可能會因為multi-thread或者是不同instance物件共享到同一個static member,而產生資料錯亂的問題。

這個問題解決方法取決於你的程式邏輯。有幾個可能做法:

  1. 將static拿掉。
  2. 將修改的method改為有同步保護的static method,例如synchronized static。