Skip to content

false positive: try-with-resource on JDK11 and later might fail with RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE #1338

@lars-sh

Description

@lars-sh

It seems, that RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE is still behaving different based on the JDK used in some situations. I expected my problems to be solved with #259, #647, #1248 or #1250, but the latest Spotbugs release didn't solve them.

I'm using Spotbugs 4.1.4 with low threshold via the Maven Spotbugs Plugin 4.1.3 and receive the error message Redundant nullcheck of inputStream, which is known to be non-null in de.larssh.pulls.IssuesSpotbugs.loadKeyStore(Path) [de.larssh.pulls.IssuesSpotbugs] Redundant null check at IssuesSpotbugs.java:[line 10] RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE.

You can find an issue showcase at https://github.com/lars-sh/parent/tree/issues-spotbugs . Just in case the links do not work in future, here's the essential code snippet:

	public static KeyStore loadKeyStore(final Path path) throws Exception {
		try (InputStream inputStream = Files.newInputStream(path)) {
			// final KeyStore keyStore = KeyStore.getInstance("JKS");
			// keyStore.load(inputStream, password.toCharArray());
			// return keyStore;
			return KeyStore.getInstance("JKS");
		}
	}

The related GitHub Action builds can be found at https://github.com/lars-sh/parent/actions?query=branch%3Aissues-spotbugs . They show, that Spotbugs do not raise a RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE for JDK 8 to 10, but raise one when compiling with JDK 11 and later.

EDIT: Migrated from Travis CI to GitHub Actions

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions