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

Stub files can no longer undo the class @NonNull annotation on, e.g., Optional #321

Closed
cpovirk opened this issue Aug 8, 2022 · 4 comments · Fixed by #325
Closed

Stub files can no longer undo the class @NonNull annotation on, e.g., Optional #321

cpovirk opened this issue Aug 8, 2022 · 4 comments · Fixed by #325

Comments

@cpovirk
Copy link

cpovirk commented Aug 8, 2022

Inside Google, we (maybe intentionally, maybe not) have a stub for java.util.Optional that undoes the class @NonNull annotation on that type, using the approach from its CFComment. As part of the upgrade from 3.21.4-eisop1 to 3.24.0-eisop1, that stops working. I notice that typetools 3.24.0 still works, so I'm wondering if this is fallout from the eisop extends @Nullable Object fixes, similar to #204, or from the eisop stub-file fix of #247. I haven't done any binary searching across releases, though, let alone commits. [edit: After writing that, I started with git bisect. But I ran into trouble because the build process doesn't automatically know which commit of stubparser to check out when building older versions.]

$ tail -n +1 X.java mystubs.astub 
==> X.java <==
import org.checkerframework.checker.nullness.qual.Nullable;

interface X {
  java.util.@Nullable Optional<String> o();
}

==> mystubs.astub <==
package java.util;
class Optional<T> {}
checker-framework-3.21.4-eisop1 $ checker/bin/javac -Astubs=mystubs.astub -processor nullness X.java
warning: /usr/local/google/home/cpovirk/checker-framework-3.21.4-eisop1/mystubs.astub: No supported annotations found! Does stub file /usr/local/google/home/cpovirk/checker-framework-3.21.4-eisop1/mystubs.astub import them?
1 warning
checker-framework-3.24.0-eisop1 $ checker/bin/javac -Astubs=mystubs.astub -processor nullness X.java
warning: /usr/local/google/home/cpovirk/checker-framework-3.24.0-eisop1/mystubs.astub: No supported annotations found! Does stub file /usr/local/google/home/cpovirk/checker-framework-3.24.0-eisop1/mystubs.astub import them?
X.java:4: error: [type.invalid.annotations.on.use] invalid type: annotations [@Initialized, @Nullable] conflict with declaration of type java.util.Optional
  java.util.@Nullable Optional<String> o();
                                       ^
1 error
1 warning
checker-framework-3.24.0 $ checker/bin/javac -Astubs=mystubs.astub -processor nullness X.java
warning: /usr/local/google/home/cpovirk/checker-framework-3.24.0/mystubs.astub: No supported annotations found! Does stub file /usr/local/google/home/cpovirk/checker-framework-3.24.0/mystubs.astub import them?
1 warning

@amalloy

wmdietl added a commit that referenced this issue Aug 16, 2022
@wmdietl
Copy link
Member

wmdietl commented Aug 16, 2022

@cpovirk Thanks for the detailed report and sorry for the trouble.
I've created a test in #324 and narrowed the issue down to being introduced in #305.

@cpovirk
Copy link
Author

cpovirk commented Aug 16, 2022

No worries, and thanks!

(Also: Ooo, I wonder if #305 helps with any of the challenges we've seen when trying to read @NullMarked from stub files from our reference checker! (It's been a while, so I forget the details.) And even if not, fixing any missing annotations is a good thing :))

@wmdietl
Copy link
Member

wmdietl commented Aug 16, 2022

Yes, #305 should fix parsing annotations e.g. in package-info.java files.
Let us get this issue fixed and then you can let us know if you're still running into issues.

@cpovirk
Copy link
Author

cpovirk commented Sep 8, 2022

This does fix our issue. Thanks!

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

Successfully merging a pull request may close this issue.

2 participants