Skip to content

Conversation

gtoison
Copy link
Contributor

@gtoison gtoison commented Aug 5, 2025

See #3573
Guava's HashBiMap is annotated with @CheckForNull and implements Map.
Potentially all Map.get() are from a HashBiMap so they would need to be checked for nullness

@iloveeclipse
Copy link
Member

I was 5 minutes too late :-)
See #3573 (comment)

@gtoison
Copy link
Contributor Author

gtoison commented Aug 5, 2025

This looks similar indeed 👍
I'm working on a fix to revert to the previous behavior but there might be a case to raise bugs for such unchecked calls, maybe in a later version of SpotBugs?

@iloveeclipse
Copy link
Member

I'm working on a fix to revert to the previous behavior

Thanks! Would be nice to have it restored.

but there might be a case to raise bugs for such unchecked calls, maybe in a later version of SpotBugs?

Sure. In fact, I highly dislike such sloppy style of programming, especially in MT related code it is always a nice surprise to developers that next get() can return not same value as before (independently on null/non null specs)...

But also with the null annotated implementation classes you never know if the given object that implement same interface would need extra checks or not, which is then again surprise at runtime.

gtoison added 2 commits August 5, 2025 11:25
When a call might be from different implementations (e.g. Map.get()
might be from HashMap or from Guava's HashBiMap) and when at least one
implementation has the CheckForNull annotation we currently don't want
the value to also have the flag.
We can revisit this later to raise potential bugs, because Map.get()
might indeed return null.
@gtoison gtoison requested a review from iloveeclipse August 5, 2025 09:38
@iloveeclipse iloveeclipse merged commit c2e18cf into spotbugs:master Aug 5, 2025
15 checks passed
@iloveeclipse
Copy link
Member

Thanks!

@JuditKnoll JuditKnoll added this to the Spotbugs 4.9.4 milestone Aug 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Inconsistent & unexpected NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE reported
3 participants