Skip to content

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

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

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>
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

1 participant