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

@Nullable prevents code from being compiled with -Werror #25095

Closed
wilkinsona opened this issue May 18, 2020 · 6 comments
Closed

@Nullable prevents code from being compiled with -Werror #25095

wilkinsona opened this issue May 18, 2020 · 6 comments

Comments

@wilkinsona
Copy link
Member

Affects: 5.2.6.RELEASE

Code that uses @Nullable cannot be compiled with -Werror due to the use of When.MAYBE on its @Nonnull meta-annotation. Attempting to compile code that depends on spring-core and that uses @Nullable results in a compilation failure:

warning: unknown enum constant When.MAYBE
  reason: class file for javax.annotation.meta.When not found
error: warnings found and -Werror specified
1 error
1 warning

Unfortunately, there's no way to suppress such warnings so I either have to abandon trying to compile with -Werror or I have to add a dependency on com.google.code.findbugs:jsr305:3.0.2.

@sdeleuze
Copy link
Contributor

sdeleuze commented May 18, 2020

Indeed, Java compiler does not trigger warning for missing annotations from the classpath except sadly when it is using such enum attribute, and we must use it. Notice this warning appears only if you are using null-safety annotations in your codebase, so end user projects won't see it until they start using our null-safety annotations in their codebase which has been evaluated as reasonably fine for Spring Framework and Spring Data.

I recommend using com.google.code.findbugs:jsr305:3.0.2 dependency as you suggested for now with provided scope or similar. Be aware that we are working on a proper replacement of JSR 305 that will not have this drawback, feel free to ping me if you want more details about that.

@jhoeller
Copy link
Contributor

Assuming that this is not a regression in a specific place but rather the same general problem since 5.0, there is indeed no way out for the time being. I'd recommend adding the dependency as well since -Werror is worth preserving for other purposes.

@bclozel bclozel removed the status: waiting-for-triage An issue we've not yet triaged or decided on label Feb 18, 2022
@skagedal
Copy link

@sdeleuze Is there an issue to follow for this, to not have to have the explicit include?

Be aware that we are working on a proper replacement of JSR 305 that will not have this drawback,

@skagedal
Copy link

Ah, I guess it's this?

@sdeleuze
Copy link
Contributor

Yes, but we may update our plans based on a potential nullness future JEP. I will update the issue you linked as we learn more.

@xenoterracide
Copy link

xenoterracide commented Feb 14, 2024

I'd like to point out that this issue could be "resolved" to some extent by simply switching findbugs jsr305 dependency to compileOnlyApi (at least for gradle users, not looking at what this creates for maven users at the moment) but that won't solve the problem with JPMS, not certain whether it would make that worse. It's the appropriate fix for this though.

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

No branches or pull requests

7 participants