You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[java] NonThreadSafeSingleton: False negative with property checkNonStaticMethods #6780
The property checkNonStaticMethods has the description:
Check for non-static methods. Do not set this to false and checkNonStaticFields to true.
The natural reading is that when checkNonStaticMethods=true, the rule checks non-static methods. However, the implementation does the opposite.
In NonThreadSafeSingletonRule.java:
if (checkNonStaticMethods && !node.isStatic()
|| node.isSynchronized()) {
returndata; // skip the method
}
When checkNonStaticMethods=true (the default), non-static methods are skipped, not checked. Conversely, setting it to false causes non-static methods to be analyzed.
This is inconsistent with the property name and description.
Minimal reproduction:
publicclassSingleton {
privatestaticSingletoninstance;
// Non-static getInstance - should be flagged by defaultpublicSingletongetInstance() {
if (instance == null) {
instance = newSingleton();
}
returninstance;
}
}
checkNonStaticMethods=true (default): non-static methods are checked.
checkNonStaticMethods=false: non-static methods are skipped.
Alternatively, if the current behavior is intentional, the property name/description should be changed to something like skipNonStaticMethods to avoid confusion.
Running PMD via: any (verified with unit tests against pmd-java 6.44.0 and 7.25.0)
changed the title [-][java] NonThreadSafeSingleton: checkNonStaticMethods property description contradicts implementation[/-][+][java] NonThreadSafeSingleton: False negative with property checkNonStaticMethods[/+]on Aug 31, 2026
Activity
[-][java] NonThreadSafeSingleton: checkNonStaticMethods property description contradicts implementation[/-][+][java] NonThreadSafeSingleton: False negative with property checkNonStaticMethods[/+]Update release notes (pmd#6780, pmd#6864)
[java] Fix #6780: NonThreadSafeSingleton checkNonStaticMethods contra…