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] CloseResource: False positive when a correctly-closed resource is declared without initializer · Issue #6742 · pmd/pmd Closed Labels a:false-positivePMD flags a piece of code that is not problematic Milestone DescriptionPMD Version: 7.24.0 SummaryPMD's
Per JLS §14.4.2 a local declaration with an initializer is exactly equivalent to a declaration followed by a separate assignment, so the two forms are semantically identical and should receive the same verdict. Reproducerbefore — declaration-with-initializer (no finding)import java.io.ByteArrayOutputStream; import java.io.ObjectOutputStream; public class SplitDeclBefore { public static void main(String[] args) throws Exception { ByteArrayOutputStream pout = new ByteArrayOutputStream(); ObjectOutputStream oout = new ObjectOutputStream(pout); oout.writeObject("x"); oout.close(); } } after — split declaration / assignment (false positive)import java.io.ByteArrayOutputStream; import java.io.ObjectOutputStream; public class SplitDeclAfter { public static void main(String[] args) throws Exception { ByteArrayOutputStream pout; pout = new ByteArrayOutputStream(); ObjectOutputStream oout; oout = new ObjectOutputStream(pout); // FALSE POSITIVE oout.writeObject("x"); oout.close(); } } Expected behavior
Actual behavior
The rule appears to register a closeable local only when it sees a same-line declarator-with-initializer; a local initialized via a separate assignment is not associated with its later Activity
MetadataMetadataAssigneesLabelsa:false-positivePMD flags a piece of code that is not problematic 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. |