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] ReturnEmptyCollectionRatherThanNull: False negative when a null value is assigned to a local that is later returned #3880
Description:
Currently, the rule ReturnEmptyCollectionRatherThanNull detects return null statements, which I think is not enough, because it is not the only way that a function can produce a null value. In the following example, function get() will return null (if flag is false), I think it should be warned.
Code Sample demonstrating the issue:
importjava.util.ArrayList;
importjava.util.List;
publicclassExampleReturnEmptyArrayRatherThanNull {
publicbooleanflag;
publicList<String> get(){
List<String> res = null; // line 8if(flag) {
res = newArrayList<>();
res.add("");
}
returnres; // line 13, false-negative
}
}
Expected outcome:
PMD should report a violation at line 13, but doesn't. This is a false-negative.
changed the title [-][java] ReturnEmptyCollectionRatherThanNull should disallow potential null return [/-][+][java] ReturnEmptyCollectionRatherThanNull: False negative on potential null return[/+]on Aug 18, 2026
changed the title [-][java] ReturnEmptyCollectionRatherThanNull: False negative on potential null return[/-][+][java] ReturnEmptyCollectionRatherThanNull: False negative when a null value is assigned to a local that is later returned[/+]on Aug 18, 2026
Activity
[java] Fix pmd#6744: Analyze possible null return values
[java] Fix pmd#6744: Analyze possible null return values
[java] Fix pmd#6744: Analyze possible null return values
[java] Fix pmd#6744: Analyze possible null return values
[java] Fix #6744: Analyze possible null return values (#6941)
[-][java] ReturnEmptyCollectionRatherThanNull should disallow potential null return [/-][+][java] ReturnEmptyCollectionRatherThanNull: False negative on potential null return[/+][-][java] ReturnEmptyCollectionRatherThanNull: False negative on potential null return[/-][+][java] ReturnEmptyCollectionRatherThanNull: False negative when a null value is assigned to a local that is later returned[/+]