Skip META-INF/ entries in classpath scanner#7461
Merged
knutwannheden merged 1 commit intomainfrom Apr 23, 2026
Merged
Conversation
`JavaSourceSet`'s classpath scanner was emitting `ShallowClass` entries for every `.class` file it found in a JAR or directory, including multi-release JAR duplicates under `META-INF/versions/N/`. For any class shipped in an MRJ, this produced two FQNs (e.g. `net.bytebuddy.asm.Advice` and `META-INF.versions.9.net.bytebuddy.asm.Advice`) that downstream consumers deduping types by FQN cannot merge, contributing to wasted type-table entries and bloated serialized LST stores. `META-INF/` is reserved for JAR metadata per the JAR spec and never contains application classes, so filter out any `.class` entries under that prefix.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
JavaSourceSet's classpath scanner emits aJavaType.ShallowClassfor every.classfile it finds in a JAR or classes directory, including multi-release JAR duplicates shipped underMETA-INF/versions/N/. For any class present in an MRJ, this produces two distinct FQNs — e.g.net.bytebuddy.asm.AdviceandMETA-INF.versions.9.net.bytebuddy.asm.Advice— that downstream consumers deduping types by FQN string cannot merge.Measured on the openrewrite/rewrite build, the top of a type-table histogram shows pairs with identical counts, one MRJ-versioned and one not:
Each visible pair is ~8-16k entries that should collapse into one. Five such pairs appear in the top 30 alone, with more in the long tail, contributing to
meta.binbloat in serialized LST stores.The classloader is responsible for interpreting MRJ layout at load time; a static classpath scan should never surface the versioned duplicates as distinct types.
Summary
JavaSourceSet.typesFromPathnow skips any.classentry whose path starts withMETA-INF/(both the JAR and directory-walk paths). Per the JAR spec that directory is reserved for metadata and never contains application classes, so broadening beyond justMETA-INF/versions/N/costs nothing and also filters any stray tooling artifacts.JavaSourceSetTestcovering a JAR with base + versioned + strayMETA-INF/entries, and the equivalent directory-tree layout.Test plan
JavaSourceSetTestfails before the fix and passes after./gradlew :rewrite-java:testgreen./gradlew :rewrite-java-test:testgreen./gradlew :rewrite-java:licenseFormatclean