Skip to content

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
PatrikScully pushed a commit to PatrikScully/spotbugs that referenced this pull request Jun 14, 2024
…ely null (spotbugs#2844)

* test: reproducer for issue spotbugs#2836

* fix: resources closed in generated finally might be definitively null

Do not report NP_LOAD_OF_KNOWN_NULL_VALUE or
RCN_REDUNDANT_NULLCHECK_OF_NULL_VALUE for the finally block generated by
the compiler

* fix: removed unnecessary code
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