You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@agrieve I can't reproduce this error with JSpecify mode enabled with NullAway 0.12.3. It does reproduce without JSpecify mode enabled. Is that what you are seeing?
Here's the list of compiler flags we're using. We don't set any flags related to which @Nullable to use, as we assume so long as it's called "@nullable" it should be treated the same.
Yeah, you're right, good catch. There are some places where we previously hardcoded support for the JSpecify @Nullable but I don't see any reason to do that anymore; we should just allow any TYPE_USE@Nullable. Will fix.
@agrieve so it turns out for annoying implementation reasons that it'll be tough to make things work completely if we don't know of some type-use @Nullable annotation that will be in the classpath. Previously we were assuming the JSpecify @Nullable annotation would be in the classpath, but that's not true in your case I think. Honestly, I'm kind of surprised that nothing else has broken for you in JSpecify mode before this.
My question is: do you have a strong reason not to have a dependence on JSpecify? If so, I'm curious what it is. If we can assume the JSpecify annotation will be in the classpath that will make things simpler for us.
Sounds like it's hard to detect that our custom @Nullable is TYPE_USE? Would be really slick if nullaway could automatically use "jspecify mode" for TYPE_USE annotations, and non-jspecify mode otherwise.
My rationale for using a custom annotation:
NullAway has other annotations as well (@Contract, @EnsuresNonNull, etc), and it's convenient for build target to have to add only a single dependency for nullable annotations instead of having to add two.
It makes it easier to package stand-alone libraries if we use our own annotation:
Not bundling them: Now users of the library need to also add a dep onto jspecify
Bundling them: Now users end up with conflicts if they also try and use jspecify
Renaming their java package when creating the .jar: adds complexity
Using our own annotations package seems by far the simplest IMO.
The "managing dependencies" problem is not exactly unique, and systems like Maven have a way to solve it, but for only two small annotations, it hardly seems worth the overhead (and we've got more than just Maven we need to be compatible with).
Sounds like it's hard to detect that our custom @Nullable is TYPE_USE? Would be really slick if nullaway could automatically use "jspecify mode" for TYPE_USE annotations, and non-jspecify mode otherwise.
The issue is that in places we need to modify javacType objects to include annotations (e.g., here), and when we do that, I think we need to choose some annotation that is in the classpath. I can tinker and see if it's possible to use some dummy internal annotation provided by NullAway instead.
My rationale for using a custom annotation:
NullAway has other annotations as well (@Contract, @EnsuresNonNull, etc), and it's convenient for build target to have to add only a single dependency for nullable annotations instead of having to add two.
It makes it easier to package stand-alone libraries if we use our own annotation:
Not bundling them: Now users of the library need to also add a dep onto jspecify
Bundling them: Now users end up with conflicts if they also try and use jspecify
Renaming their java package when creating the .jar: adds complexity
Using our own annotations package seems by far the simplest IMO.
The "managing dependencies" problem is not exactly unique, and systems like Maven have a way to solve it, but for only two small annotations, it hardly seems worth the overhead (and we've got more than just Maven we need to be compatible with).
While I totally get it in general (and NullAway itself really tries to avoid adding new deps for exactly these reasons), for JSpecify in particular I think it is extremely unlikely that users will ever end up with conflicts if you bundle its current annotations. @cpovirk could perhaps comment further, but I cannot imagine a scenario in which JSpecify introduces an incompatible version of these annotations in a future version (though new annotations may be added). So maybe bundling (without shadowing) is an ok solution in this case?
I can repro this warning even when jspecify is on the classpath. If having it on the classpath would fix the issue, that would be an easy thing to ensure (I can just add it when running the checks).
Most android apps use R8 to do whole-program optimization, and it gets upset when given duplicate classes, even if they are the same.
Ok, got it. So I'll try to fix this issue, with the assumption that the JSpecify @Nullable annotation will be on the classpath. I'll also make NullAway fail in JSpecify mode if the JSpecify @Nullable annotation is not on the classpath; perhaps we will find a workaround in the future.
The issue is that in places we need to modify javacType objects to include annotations (e.g., here), and when we do that, I think we need to choose some annotation that is in the classpath. I can tinker and see if it's possible to use some dummy internal annotation provided by NullAway instead.
Just as an aside, we have seen a similar problem with our JSpecify reference checker. In that case, we need an annotation on the classpath for the Checker Framework's purposes. I think that's different from your case, in which you're trying to produce instances of javac types more just because you ought to be able to use the javac types (and have successfully done so elsewhere) but can't in case of the weird javac behavior for some cases? I wish that I understood the Checker Framework dataflow model better to understand whether you might eventually need annotations on the classpath for it, too (perhaps for conversions between type variables and their bounds?). But hopefully it will be fine to require the JSpecify annotations on the classpath during nullness checking.
In the reference checker, we ended up having users put a special jar of package-private annotations on the classpath for us to use. I don't love that approach, since a static analyzer would ideally live entirely on the processorpath. I will say that I've wondered if we could just use, say, @Override and @FunctionalInterface as our internal @Nullable and @NonNull: javac probably doesn't have any reason to validate that they're actually type annotations. (Now, I think the Checker Framework has some logic somewhere that is conditional on annotation @Target values, so that might not go well. But I don't think we'd be using the trick in that area of the code.)
Activity
msridhar commentedon Jan 31, 2025
@agrieve I can't reproduce this error with JSpecify mode enabled with NullAway 0.12.3. It does reproduce without JSpecify mode enabled. Is that what you are seeing?
agrieve commentedon Feb 5, 2025
Ah, so the error goes away if I use jspecify's @nullable, but when I use Chrome's
@Nullable, the error shows.Our
@Nullableis here.Here's the list of compiler flags we're using. We don't set any flags related to which
@Nullableto use, as we assume so long as it's called "@nullable" it should be treated the same.msridhar commentedon Feb 5, 2025
Yeah, you're right, good catch. There are some places where we previously hardcoded support for the JSpecify
@Nullablebut I don't see any reason to do that anymore; we should just allow anyTYPE_USE@Nullable. Will fix.msridhar commentedon Feb 6, 2025
@agrieve so it turns out for annoying implementation reasons that it'll be tough to make things work completely if we don't know of some type-use
@Nullableannotation that will be in the classpath. Previously we were assuming the JSpecify@Nullableannotation would be in the classpath, but that's not true in your case I think. Honestly, I'm kind of surprised that nothing else has broken for you in JSpecify mode before this.My question is: do you have a strong reason not to have a dependence on JSpecify? If so, I'm curious what it is. If we can assume the JSpecify annotation will be in the classpath that will make things simpler for us.
agrieve commentedon Feb 6, 2025
Sounds like it's hard to detect that our custom
@NullableisTYPE_USE? Would be really slick if nullaway could automatically use "jspecify mode" forTYPE_USEannotations, and non-jspecify mode otherwise.My rationale for using a custom annotation:
@Contract,@EnsuresNonNull, etc), and it's convenient for build target to have to add only a single dependency for nullable annotations instead of having to add two.The "managing dependencies" problem is not exactly unique, and systems like Maven have a way to solve it, but for only two small annotations, it hardly seems worth the overhead (and we've got more than just Maven we need to be compatible with).
msridhar commentedon Feb 6, 2025
The issue is that in places we need to modify
javacTypeobjects to include annotations (e.g., here), and when we do that, I think we need to choose some annotation that is in the classpath. I can tinker and see if it's possible to use some dummy internal annotation provided by NullAway instead.While I totally get it in general (and NullAway itself really tries to avoid adding new deps for exactly these reasons), for JSpecify in particular I think it is extremely unlikely that users will ever end up with conflicts if you bundle its current annotations. @cpovirk could perhaps comment further, but I cannot imagine a scenario in which JSpecify introduces an incompatible version of these annotations in a future version (though new annotations may be added). So maybe bundling (without shadowing) is an ok solution in this case?
agrieve commentedon Feb 6, 2025
I can repro this warning even when jspecify is on the classpath. If having it on the classpath would fix the issue, that would be an easy thing to ensure (I can just add it when running the checks).
Most android apps use R8 to do whole-program optimization, and it gets upset when given duplicate classes, even if they are the same.
msridhar commentedon Feb 6, 2025
Ok, got it. So I'll try to fix this issue, with the assumption that the JSpecify
@Nullableannotation will be on the classpath. I'll also make NullAway fail in JSpecify mode if the JSpecify@Nullableannotation is not on the classpath; perhaps we will find a workaround in the future.agrieve commentedon Feb 6, 2025
Sounds great!
cpovirk commentedon Feb 6, 2025
Just as an aside, we have seen a similar problem with our JSpecify reference checker. In that case, we need an annotation on the classpath for the Checker Framework's purposes. I think that's different from your case, in which you're trying to produce instances of javac types more just because you ought to be able to use the javac types (and have successfully done so elsewhere) but can't in case of the weird javac behavior for some cases? I wish that I understood the Checker Framework dataflow model better to understand whether you might eventually need annotations on the classpath for it, too (perhaps for conversions between type variables and their bounds?). But hopefully it will be fine to require the JSpecify annotations on the classpath during nullness checking.
In the reference checker, we ended up having users put a special jar of package-private annotations on the classpath for us to use. I don't love that approach, since a static analyzer would ideally live entirely on the processorpath. I will say that I've wondered if we could just use, say,
@Overrideand@FunctionalInterfaceas our internal@Nullableand@NonNull: javac probably doesn't have any reason to validate that they're actually type annotations. (Now, I think the Checker Framework has some logic somewhere that is conditional on annotation@Targetvalues, so that might not go well. But I don't think we'd be using the trick in that area of the code.)msridhar commentedon Feb 7, 2025
In the end, I found a trick so that we don't even need the JSpecify
@Nullableannotation on the classpath, at least for now. (Basically, we just use whatever@Nullableannotation type we found in the code: https://github.com/uber/NullAway/pull/1142/files#diff-ff27cbf7ec2f2f43a39e36ffc3a820771afadf439b803a5b1167d347ae316dceR75) As @cpovirk notes, as we add more JSpecify support we may run into a need to have those annotations on the classpath at some point. But for now, we have escaped 🙂agrieve commentedon Feb 7, 2025
That's great! Thank you!
Remove need to use JSpecify's @nullable annotation (#1142)
Roll NullAway 0.12.3 -> 0.12.4
Roll NullAway 0.12.3 -> 0.12.4
Roll NullAway 0.12.3 -> 0.12.4