GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — [java] ReturnEmptyCollectionRatherThanNull: False negative when null is returned through a local variable · Issue #6695 · pmd/pmd Closed Labels a:false-negativePMD doesn't flag a problematic piece of code Milestone DescriptionAffects PMD Version: 7.24.0 Rule: ReturnEmptyCollectionRatherThanNull — https://docs.pmd-code.org/latest/pmd_rules_java_errorprone.html#returnemptycollectionratherthannull Description:
Code Sample demonstrating the issue: import java.util.List; import java.util.ArrayList; public class ReturnNullDemo { private final List<String> items = new ArrayList<>(); // BEFORE — correctly flagged by ReturnEmptyCollectionRatherThanNull public int[] getNumbersBefore(boolean empty) { if (empty) { return null; // <-- reported } return new int[] { 1, 2, 3 }; } public List<String> getItemsBefore(boolean absent) { if (absent) { return null; // <-- reported } return items; } // AFTER — semantically identical, NOT flagged (false-negative) public int[] getNumbersAfter(boolean empty) { if (empty) { int[] result = null; return result; // <-- NOT reported, but still returns null } return new int[] { 1, 2, 3 }; } public List<String> getItemsAfter(boolean absent) { if (absent) { List<String> result = null; return result; // <-- NOT reported, but still returns null } return items; } } Expected outcome: Actual outcome: The rule reports only the two BEFORE methods; the AFTER methods (where Running PMD through: CLI Activity
MetadataMetadataAssigneesLabelsa:false-negativePMD doesn't flag a problematic piece of code TypeProjectsMilestoneRelationshipsDevelopmentIssue actions |
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |