Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

False positive RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE and NP_LOAD_OF_KNOWN_NULL_VALUE when using empty try-with-resources #647

Closed
nickantzoulis opened this issue Jun 1, 2018 · 5 comments

Comments

@nickantzoulis
Copy link

public void falsePositive(Path myPath) throws IOException {
    try (InputStream inStream = java.nio.file.Files.newInputStream(myPath)) {
       // commented out code
    }
}

The preceding code produces 2 false positives:
-RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE
-NP_LOAD_OF_KNOWN_NULL_VALUE

Using jdk 1.8.0_172, spotbugs version 3.1.3

@KengoTODA KengoTODA marked this as a duplicate of #259 Nov 19, 2018
@KengoTODA KengoTODA marked this as not a duplicate of #259 Nov 19, 2018
@KengoTODA KengoTODA reopened this Nov 19, 2018
@nmatt
Copy link

nmatt commented May 8, 2019

I have this same problem with SpotBugs 3.1.12.
@KengoTODA: What info do you need?

@KengoTODA
Copy link
Member

@nmatt better to have a test case that reproduce this issue. Check our contribution guide for detail.

@KengoTODA
Copy link
Member

#259 has been closed by v4.1.3, please have a try.

@dwalluck
Copy link

dwalluck commented Oct 6, 2020

In my project, the 4.1.3 release fixed all RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE issues, but I still seem to have RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE in try-with-resources.

Can you verify whether these two are false positives?

https://github.com/project-ncl/build-finder/blob/76f54434c4dd32366cdbd995d7664176f83eba31/cli/src/main/java/org/jboss/pnc/build/finder/cli/Main.java#L657

https://github.com/project-ncl/build-finder/blob/76f54434c4dd32366cdbd995d7664176f83eba31/cli/src/main/java/org/jboss/pnc/build/finder/cli/Main.java#L716

@dwalluck
Copy link

dwalluck commented Oct 6, 2020

@KengoTODA Error: Low: Redundant nullcheck of session, which is known to be non-null in org.jboss.pnc.build.finder.cli.Main.call() [org.jboss.pnc.build.finder.cli.Main, org.jboss.pnc.build.finder.cli.Main] Redundant null check at Main.java:[line 657]Another occurrence at Main.java:[line 716] RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE

project-ncl/build-finder#237

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants