-
Notifications
You must be signed in to change notification settings - Fork 299
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
NullAway doesn't recognize @Nullable annotation in a different compilation unit #1011
Comments
Hi @gavlyukovskiy, one caveat is that our JSpecify mode checks are still limited. That said I think your specific test case should work. You may be running into #1005. Any chance you could try compiling using JDK 22 and see if that fixes the problem? |
This is very interesting, thanks for reporting. I can reproduce the problem, even on JDK 22, and I've pushed a test case here. This to me looks like a bug in javac. NullAway gets the type for the lambda being passed as a parameter here:
On JDK 21, this type is @cushon @cpovirk do you agree this is potentially a bug in javac's reading of type-use annotations from bytecode? Is this a known issue? |
FWIW, here is what I see for the
I'm pretty sure
|
That's an interesting find. It seems like it already puts an annotation on the first argument as well for |
@gavlyukovskiy I've confirmed this is an issue in javac. I'll put updates here as there is progress towards a fix. |
Thank you @msridhar |
I should say a bit more here. This test case exposes a new issue on JDK 22+. On JDK 21 and earlier the issue with not reading type annotations from bytecode was already known and is covered by #1005 |
There is now a PR openjdk/jdk#20460 up to fix this issue. Once a fix lands, it will have to get into a released JDK before NullAway users can benefit from it. Thank you again for reporting this! I will leave this issue open until a fix reaches a JDK release. |
We can enable the test on appropriate JDK versions once openjdk/jdk#20460 lands. #1011
Small update here. The above PR has landed and will ship with JDK 24. There is a backport for JDK 23: openjdk/jdk23u#67 Assuming the backport goes through, I think this would be fixed in the first patch release of JDK 23 (it's too late to make the GA release). |
Thank you for the update @msridhar! It might be a wrong place to ask, but is there any chance such a fix will be backported to jdk21u? |
@gavlyukovskiy there is an effort to get related fixes for reading of type annotations from bytecodes backported to JDK 21 and possibly earlier. See jspecify/jspecify#365, https://bugs.openjdk.org/browse/JDK-8323093, and https://mail.openjdk.org/pipermail/compiler-dev/2024-July/027344.html. At this point, I imagine that if that backport is approved, the fixes for this issue would be included. /cc @cushon |
I've been migrating on of our projects to jspecify and noticed that NullAway reports nullability problems for passing null values to the
@Nullable
generic parameters in another compilation unit (main source set).src/main/java
:src/test/java
:Compiling the test class gives the following error:
I've also tried extracting the expression into
Function<String, @Nullable String>
variable, but passing that gives slightly different error:I've tried the same test but without generic parameters:
and both main and test source sets react to it correctly (both with and without
@Nullable
annotation), so the problems appears to be with generics.I've tried reproducing the situation inside
com.uber.nullaway.jspecify.GenericsTests
, but as they're the same compilation unit it wasn't possible.Reproducer: https://github.com/gavlyukovskiy/nullaway-reproducer (
./gradlew build
)Versions:
The text was updated successfully, but these errors were encountered: