Skip to content

Shaded google dependency points to dangling annotation references #4436

Closed as not planned

Description

@bclozel

Hi team,

I have been running Spring for GraphQL tests against GraphQL Java 26.0 for a while now.
But as I'm preparing for the next minor version, I am trying to compile the project against 26.0 and getting compiler warnings like this.

:spring-graphql:compileJava FAILED	
/Users/bclozel/.gradle/caches/modules-2/files-2.1/com.graphql-java/graphql-java/26.0/d1a1d3005ca6f4a87b4a985a1907b22bf5b63700/graphql-java-26.0.jar(/graphql/com/google/common/collect/ImmutableList.class): warning: [classfile] Cannot find annotation method 'serializable()' in type 'GwtCompatible': class file for com.google.common.annotations.GwtCompatible not found	
/Users/bclozel/.gradle/caches/modules-2/files-2.1/com.graphql-java/graphql-java/26.0/d1a1d3005ca6f4a87b4a985a1907b22bf5b63700/graphql-java-26.0.jar(/graphql/com/google/common/collect/ImmutableList.class): warning: [classfile] Cannot find annotation method 'emulated()' in type 'GwtCompatible'	
/Users/bclozel/.gradle/caches/modules-2/files-2.1/com.graphql-java/graphql-java/26.0/d1a1d3005ca6f4a87b4a985a1907b22bf5b63700/graphql-java-26.0.jar(/graphql/com/google/common/collect/ImmutableList.class): warning: [classfile] Cannot find annotation method 'value()' in type 'DoNotCall': class file for com.google.errorprone.annotations.DoNotCall not found	
/Users/bclozel/.gradle/caches/modules-2/files-2.1/com.graphql-java/graphql-java/26.0/d1a1d3005ca6f4a87b4a985a1907b22bf5b63700/graphql-java-26.0.jar(/graphql/com/google/common/collect/ImmutableList.class): warning: [classfile] Cannot find annotation method 'value()' in type 'DoNotCall'	
/Users/bclozel/.gradle/caches/modules-2/files-2.1/com.graphql-java/graphql-java/26.0/d1a1d3005ca6f4a87b4a985a1907b22bf5b63700/graphql-java-26.0.jar(/graphql/com/google/common/collect/ImmutableList.class): warning: [classfile] Cannot find annotation method 'value()' in type 'DoNotCall'	
/Users/bclozel/.gradle/caches/modules-2/files-2.1/com.graphql-java/graphql-java/26.0/d1a1d3005ca6f4a87b4a985a1907b22bf5b63700/graphql-java-26.0.jar(/graphql/com/google/common/collect/ImmutableList.class): warning: [classfile] Cannot find annotation method 'value()' in type 'DoNotCall'	
/Users/bclozel/.gradle/caches/modules-2/files-2.1/com.graphql-java/graphql-java/26.0/d1a1d3005ca6f4a87b4a985a1907b22bf5b63700/graphql-java-26.0.jar(/graphql/com/google/common/collect/ImmutableList.class): warning: [classfile] Cannot find annotation method 'value()' in type 'DoNotCall'	
/Users/bclozel/.gradle/caches/modules-2/files-2.1/com.graphql-java/graphql-java/26.0/d1a1d3005ca6f4a87b4a985a1907b22bf5b63700/graphql-java-26.0.jar(/graphql/com/google/common/collect/ImmutableList.class): warning: [classfile] Cannot find annotation method 'value()' in type 'DoNotCall'	
/Users/bclozel/.gradle/caches/modules-2/files-2.1/com.graphql-java/graphql-java/26.0/d1a1d3005ca6f4a87b4a985a1907b22bf5b63700/graphql-java-26.0.jar(/graphql/com/google/common/collect/ImmutableList.class): warning: [classfile] Cannot find annotation method 'replacement()' in type 'InlineMe': class file for com.google.errorprone.annotations.InlineMe not found	
error: warnings found and -Werror specified

This is breaking my build since it's compiling with javac -Xlint:classfile -Werror

It looks like 26.0 shades relocated Guava classes (like graphql.com.google.common.collect.ImmutableList) whose bytecode still carries RuntimeInvisibleAnnotations referencing the original relocated annotation
types:

  • com.google.common.annotations.GwtCompatible
  • com.google.errorprone.annotations.DoNotCall
  • com.google.errorprone.annotations.InlineMe

Those classes are not present in the jar and this causes the compiler issues.

You can reproduce this with a minimal build like and run compileJava:

dependencies {
    implementation 'com.graphql-java:graphql-java:26.0'
}

tasks.withType(JavaCompile).configureEach {
    options.compilerArgs += ['-Xlint:classfile', '-Werror']
}

I can't reproduce this with 25.0, but I'm not sure when/how this was introduced.
I guess the shadowJar task configuration must be updated to avoid such problems.

Activity

  1. bclozel commented on Aug 19, 2026

    @bclozel
    Author

    I spent a bit more time looking into this problem.

    Annotations that are RuntimeInvisibleAnnotations are indeed not used or read at runtime, but the java compiler reads those when it loads the class at compile time. Here, @GwtCompatible, @DoNotCall and others are used for static analysis and are not read at runtime. If one of those annotations is missing at compile time, the compiler can't fully resolve it and we get a compiler warning.

    It seems that the shadowing configuration didn't change, and the guava version isn't responsible either. In fact, it seems that this problem has been around for long and only materialized recently because of other code changes.

    I have found two changes that might explain that ImmutableList is now more broadly exposed to consumers (whereas before this was kept private within implementations):

    1. 2e7c4fc introduced ImmutableList on public methods in the execution package
    2. e12c074 is a more subtle change; I believe the type can be loaded by the compiler because it's now visible in a lambda. I'm not 100% sure on that one though.

    So to summarize, this is not a new problem but this was exposed more broadly in 26.0. The very nature of guava types makes them hard to contain: even if you adopt an architecture rule that prevents them from being exposed on public signatures, they might appear at compile time through lambdas and other language constructs.

  2. bclozel commented on Aug 20, 2026

    @bclozel
    Author

    This has been fixed by #4445.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions