Skip to content

[java] CloseResource: false positive with reassignment detection #2977

@djh82

Description

@djh82

Rule: CloseResource

Upgraded to 6.30.0, having previously been using 6.28.0. Now seeing false positives with the CloseResource rule, with this contrived example:

import java.io.RandomAccessFile;

public class FalsePositive {
    private boolean isHundredBytes = false;

    public void bar() throws Exception {
        RandomAccessFile file = null;
        try {
            file = new RandomAccessFile("name", "r");
            this.isHundredBytes = file.length() == 100;  /* violation here... */
        } finally {
            file.close();
        }
    }
}

Metadata

Metadata

Assignees

Labels

a:false-positivePMD flags a piece of code that is not problematic

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions