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 positives for try-with-resources when the resource is definitively null #2844

Merged
merged 4 commits into from
Jan 27, 2024

Conversation

gtoison
Copy link
Contributor

@gtoison gtoison commented Jan 27, 2024

When a try-with-resource has a branch where the resource is definitively null false positive NP_LOAD_OF_KNOWN_NULL_VALUE and RCN_REDUNDANT_NULLCHECK_OF_NULL_VALUE are reported, for instance for that code sample:

	try (InputStream input = Issue2836.class.getResourceAsStream(resource)) {
		if (input == null) {
			return null;
		} else {
			return "test";
		}
	}

Fixes #2836

@hazendaz hazendaz added this to the SpotBugs 4.8.4 milestone Jan 27, 2024
@hazendaz hazendaz self-assigned this Jan 27, 2024
@hazendaz hazendaz merged commit 9c565e9 into spotbugs:master Jan 27, 2024
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

False positives for try-with-resources (NP_LOAD_OF_KNOWN_NULL_VALUE, RCN_REDUNDANT_NULLCHECK_OF_NULL_VALUE)
2 participants