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

Missing sources for type annotations trip the compiler #10020

Closed
zbynek opened this issue Oct 28, 2024 · 2 comments · Fixed by #10021
Closed

Missing sources for type annotations trip the compiler #10020

zbynek opened this issue Oct 28, 2024 · 2 comments · Fixed by #10021
Milestone

Comments

@zbynek
Copy link
Collaborator

zbynek commented Oct 28, 2024

GWT version: 2.11
Browser (with version): any
Operating System: Windows


Description

Some usages of annotations lead to missing source errrors.

Steps to reproduce

Usecase 1)

  • Add jsinterop 1.0.2 to your project
  • Compile with GWT 2.11
[ERROR] Errors in 'jar:file:/.../base-1.0.2.jar!/jsinterop/base/Js.java'
         [ERROR] Line 140: Nullable cannot be resolved to a type

Usecase 2
Same issue also reproducible with j2objc annotations 2.8, depending on placement. Annotating a field is OK

@WeakOuter Object foo = new Object();

Annotating an anonymous class is not

foo =  new @WeakOuter Object() {
   @Override
   public String toString() {
      return "Foo";
   }
}
Known workarounds
  • Include all annotation sources
Links to further discussions

google/jsinterop-base#19

@cpovirk
Copy link
Contributor

cpovirk commented Oct 29, 2024

I got asked if I could share how to reproduce the trouble we've seen with this in Guava.

It's pretty easy: Currently, we strip out our type-use nullness annotations to avoid that problem. So I pushed a commit to my Guava fork to stop stripping them. With that change, I can run ./mvnw clean install -DskipTests, and I get a flood of errors like this:

[INFO] Tracing compile failure path for type 'com.google.common.collect.SortedSetMultimap'
[INFO]    [ERROR] Errors in 'file:/usr/local/google/home/cpovirk/clients/guava-black/guava/guava-gwt/target/classes/com/google/common/collect/SortedSetMultimap.java'
[INFO]       [ERROR] Line 53: No source code is available for type org.checkerframework.checker.nullness.qual.Nullable; did you forget to inherit a required module?
[INFO]    [ERROR] Errors in 'file:/usr/local/google/home/cpovirk/clients/guava-black/guava/guava-gwt/target/classes/com/google/common/collect/SetMultimap.java'
[INFO]       [ERROR] Line 56: No source code is available for type org.checkerframework.checker.nullness.qual.Nullable; did you forget to inherit a required module?
[INFO]    [ERROR] Errors in 'file:/usr/local/google/home/cpovirk/clients/guava-black/guava/guava-gwt/target/classes/com/google/common/collect/Multimap.java'
[INFO]       [ERROR] Line 168: No source code is available for type org.checkerframework.checker.nullness.qual.Nullable; did you forget to inherit a required module?
[INFO]    [ERROR] Errors in 'file:/usr/local/google/home/cpovirk/clients/guava-black/guava/guava-gwt/target/classes/com/google/common/collect/Multiset.java'
[INFO]       [ERROR] Line 98: No source code is available for type org.checkerframework.checker.nullness.qual.Nullable; did you forget to inherit a required module?

@niloc132
Copy link
Member

I've put up a PR with a test that reflects the six different ways that JDT can encounter annotations, and I think this simple fix will resolve this bug.

@niloc132 niloc132 added this to the 2.13 milestone Oct 29, 2024
niloc132 added a commit that referenced this issue Nov 7, 2024
JDT supports three kinds of annotations, and the ASTVisitor lets them be
encountered in two different scopes. This patch ensures that all six
cases are handled, and adds a test that uses each of the six cases -
removing any one of the `visit` implementations will fail the test by
incorrectly reporting the annotation as not having sources available.

Fixes #10020
niloc132 added a commit to niloc132/gwt that referenced this issue Nov 7, 2024
…#10021)

JDT supports three kinds of annotations, and the ASTVisitor lets them be
encountered in two different scopes. This patch ensures that all six
cases are handled, and adds a test that uses each of the six cases -
removing any one of the `visit` implementations will fail the test by
incorrectly reporting the annotation as not having sources available.

Fixes gwtproject#10020
niloc132 added a commit that referenced this issue Nov 11, 2024
JDT supports three kinds of annotations, and the ASTVisitor lets them be
encountered in two different scopes. This patch ensures that all six
cases are handled, and adds a test that uses each of the six cases -
removing any one of the `visit` implementations will fail the test by
incorrectly reporting the annotation as not having sources available.

Fixes #10020
See #10021
copybara-service bot pushed a commit to google/truth that referenced this issue Nov 14, 2024
We already strip `@Nullable` because of [a GWT bug with type-use annotations](gwtproject/gwt#10020) (recently fixed!). But because of our usages of `@NullMarked`, the `@Nullable` stripping makes all types non-null. To avoid that, we strip `@NullMarked`, too.

RELNOTES=Changed our GWT/J2CL artifact to omit usages of `@NullMarked`. This was making all our types non-null in those environments, since we don't yet use `@Nullable` in the GWT/J2CL artifact.
PiperOrigin-RevId: 696631127
copybara-service bot pushed a commit to google/truth that referenced this issue Nov 26, 2024
We already strip `@Nullable` because of [a GWT bug with type-use annotations](gwtproject/gwt#10020) (recently fixed!). But because of our usages of `@NullMarked`, the `@Nullable` stripping makes all types non-null. To avoid that, we strip `@NullMarked`, too.

RELNOTES=Changed our GWT/J2CL artifact to omit usages of `@NullMarked`. This was making all our types non-null in those environments, since we don't yet use `@Nullable` in the GWT/J2CL artifact.
PiperOrigin-RevId: 696631127
copybara-service bot pushed a commit to google/truth that referenced this issue Nov 26, 2024
We already strip `@Nullable` because of [a GWT bug with type-use annotations](gwtproject/gwt#10020) (recently fixed!). But because of our usages of `@NullMarked`, the `@Nullable` stripping makes all types non-null. To avoid that, we strip `@NullMarked`, too.

RELNOTES=Changed our GWT/J2CL artifact to omit usages of `@NullMarked`. This was making all our types non-null in those environments, since we don't yet use `@Nullable` in the GWT/J2CL artifact.
PiperOrigin-RevId: 700266827
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.

3 participants