JD.SYNC.IN

JD.SYNC.IN is found when a class is using its own field inconsistently. "Inconsistently" means that the number of protected usages is greater than 66% of the number of all usages. The error is reported when the count of field usages is greater than three. These numbers are checker parameters that you can change.

Vulnerability and risk

Inconsistent synchronization can cause race conditions.

Mitigation and prevention

Fields should either be synchronized with the same lock all the time, or not synchronized at all. Partial synchronization is a root-cause of race condition problems.

Example 1

Copy
      class MyClass {
         private String name;
         public MyClass() {
             name = "";
         }
         synchronized public String getName() {
             return name;
         }
         synchronized public void setName(String name) {
             this.name = name;
         }
         public void foo(String x) {
             name = x;
         }
     }

JD.SYNC.IN is reported for field declaration on line 10: Field 'name' synchronized inconsistently.