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

In JSpecify mode, missing meta-annotations trigger warning i.c.w. JDK 23+ #1171

Closed
Stephan202 opened this issue Mar 22, 2025 · 1 comment
Closed

Comments

@Stephan202
Copy link

See this discussion for context. I narrowed down the reproduction case to:

import reactor.core.publisher.Mono;

final class Test {
  void m() {
    Mono.justOrEmpty(null);
  }
}

In the absence of a dependency on com.google.code.findbugs:jsr305 (or similar org.jspecify:jspecify alternative), this triggers the following warning:

[WARNING] Cannot find annotation method 'when()' in type 'javax.annotation.Nonnull': class file for javax.annotation.Nonnull not found
[WARNING] /path/to/Test.java: unknown enum constant javax.annotation.meta.When.MAYBE
  reason: class file for javax.annotation.meta.When not found

The trigger seems to be this usage of reactor.util.annotation.Nullable, which is defined with reference to a few javax.annotation.* meta annotations.

The issue is not observed without -XepOpt:NullAway:JSpecifyMode=true. I could also not reproduce it with JDK 21.0.6-tem and 22.0.2-oracle, but do observe it with 23.0.2-tem and 24-open. This indicates that it's specific to JSpecify mode on JDK 23+.

@msridhar
Copy link
Collaborator

I can reproduce this in a standalone build, but it's hard to reproduce in a unit test, so hard to track down exactly what is going on. That said, what I think is going on is:

  1. From JDK 23 on, more annotations get read from bytecodes via the Compiler Tree APIs, due to fixes in javac;
  2. In JSpecify mode, we are calling one of these APIs on this method parameter that we didn't call before (due to some generics checking); and
  3. reading the annotation via the Compiler Tree API leads to the annotation type being properly loaded by javac, which leads to its meta-annotations being loaded, which leads to the warning you are seeing.

The only part I'm not too sure about is why 2 is happening (which is hard to track down outside a unit test). But I don't think anything wrong is going on here. javac tries to be lazy about loading types / annotations from the classpath, but in principle it can load whatever is present there and whatever those types depend on. By using javax.annotations.* meta annotations, I think those annotations become part of reactor.util.annotation.Nullable's "API" and should be on the classpath to avoid such warnings.

While I haven't fully tracked this down, I'm pretty sure it's not a NullAway bug, so I'm going to close it out. Unfortunately I think you'll need the JSR305 annotations on the classpath to avoid these warnings for now.

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

2 participants