Skip to content

Fix shaded Guava annotation refs breaking -Xlint:classfile consumers - #4437

Closed
kalayciburak wants to merge 1 commit into
graphql-java:masterfrom
kalayciburak:fix/4436-shadow-annotation-refs
Closed

Fix shaded Guava annotation refs breaking -Xlint:classfile consumers#4437
kalayciburak wants to merge 1 commit into
graphql-java:masterfrom
kalayciburak:fix/4436-shadow-annotation-refs

Conversation

@kalayciburak

Copy link
Copy Markdown

Summary

Fixes #4436.

The published jar shades a minimized subset of Guava under graphql.com.google.common, but classfiles such as ImmutableList keep RuntimeInvisibleAnnotations that reference annotation types that were never included:

  • com.google.common.annotations.GwtCompatible (and related)
  • com.google.errorprone.annotations.DoNotCall / InlineMe / …
  • com.google.j2objc.annotations.*
  • org.checkerframework.*
  • javax.annotation.*

Consumers that compile with -Xlint:classfile -Werror (reported from Spring for GraphQL against 26.0) fail with Cannot find annotation method … class file for … not found.

Change

  • Relocate those annotation packages alongside Guava and include the corresponding jars in shadowJar (with minimize excludes so they are retained).
  • Keep OSGi Import-Package from re-exporting the shaded packages.
  • Exclude the new shaded trees from JaCoCo class directories.
  • Add verifyShadedJarAnnotationRefs (wired into check / after buildNewJar) and ShadedJarAnnotationRefsTest so a regression fails the packaging pipeline.

Test plan

Executed locally:

  • RED: javac --release 17 -Xlint:classfile -Werror -cp <published-jar> … against graphql.com.google.common.collect.ImmutableList failed with missing GwtCompatible / DoNotCall / InlineMe classfiles
  • GREEN: same consumer compile after the change (exit 0)
  • ./gradlew shadowJar verifyShadedJarAnnotationRefs SUCCESS
  • ./gradlew test --tests graphql.ShadedJarAnnotationRefsTest --tests graphql.GuavaLimitCheck --tests 'graphql.collect.*' --tests 'graphql.relay.*' — 38 tests GREEN

Relocate and ship Guava annotation packages (common.annotations,
errorprone, j2objc, checker-qual, jsr305) with the minimized Guava
shade so RuntimeInvisibleAnnotations on ImmutableList and friends no
longer point at types absent from the published jar.

Consumers compiling with -Xlint:classfile -Werror (e.g. Spring for
GraphQL) failed on those dangling descriptors. Add a packaging check
and Spock guard for the published jar.

Fixes graphql-java#4436

Signed-off-by: Burak KALAYCI <kalayciburak1996@gmail.com>
@bclozel

bclozel commented Aug 19, 2026

Copy link
Copy Markdown

@kalayciburak did you check how much this adds to the resulting JAR? Is this only adding the relevant classes or the entire contents of the JAR because those are excluded from the minimize task?

@kalayciburak

Copy link
Copy Markdown
Author

minimize exclude pulls the whole annotation jars, not just the types the shaded Guava classfiles point at.

on 26.0 (3.7mb) thats about +270kb, almost all checker-qual (~224kb). jsr305 + error_prone + j2objc together are ~45kb. the classfiles only actually reference 26 annotation types though, ~7kb compressed if we keep just those.

i can slim it to the referenced types if youd rather not ship the rest.

@bclozel

bclozel commented Aug 19, 2026

Copy link
Copy Markdown

@kalayciburak I'm not part of the graphql-java team so I'll defer to them. I was wondering about the implications of this change. I tried myself to implement an alternative fix, but this involves listing all the relevant annotations manually - so pretty hard to maintain and test.

While this problem is still worth looking into, I have also found new information.

@kalayciburak

Copy link
Copy Markdown
Author

looks like #4445 already landed the annotation cleanup on master, so this include-the-jars approach is obsolete. closing

@andimarek

Copy link
Copy Markdown
Member

Sorry for not commenting earlier @kalayciburak : we appreciate all contributions and your PR helped us to decide how to solve it. 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 this pull request may close these issues.

Shaded google dependency points to dangling annotation references

3 participants