Skip to content

Skip META-INF/ entries in classpath scanner#7461

Merged
knutwannheden merged 1 commit intomainfrom
skip-meta-inf/versions/n-in-classpath-scanner
Apr 23, 2026
Merged

Skip META-INF/ entries in classpath scanner#7461
knutwannheden merged 1 commit intomainfrom
skip-meta-inf/versions/n-in-classpath-scanner

Conversation

@knutwannheden
Copy link
Copy Markdown
Contributor

Motivation

JavaSourceSet's classpath scanner emits a JavaType.ShallowClass for every .class file it finds in a JAR or classes directory, including multi-release JAR duplicates shipped under META-INF/versions/N/. For any class present in an MRJ, this produces two distinct FQNs — e.g. net.bytebuddy.asm.Advice and META-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:

8053  ShallowClass  META-INF.versions.9.net.bytebuddy.asm.Advice
8053  ShallowClass  net.bytebuddy.asm.Advice
6859  ShallowClass  net.bytebuddy.agent.builder.AgentBuilder
6859  ShallowClass  META-INF.versions.9.net.bytebuddy.agent.builder.AgentBuilder
...

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.bin bloat 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.typesFromPath now skips any .class entry whose path starts with META-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 just META-INF/versions/N/ costs nothing and also filters any stray tooling artifacts.
  • Adds JavaSourceSetTest covering a JAR with base + versioned + stray META-INF/ entries, and the equivalent directory-tree layout.

Test plan

  • New JavaSourceSetTest fails before the fix and passes after
  • ./gradlew :rewrite-java:test green
  • ./gradlew :rewrite-java-test:test green
  • ./gradlew :rewrite-java:licenseFormat clean

`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.
@github-project-automation github-project-automation Bot moved this to In Progress in OpenRewrite Apr 23, 2026
@knutwannheden knutwannheden merged commit 2b4cbc0 into main Apr 23, 2026
1 check passed
@knutwannheden knutwannheden deleted the skip-meta-inf/versions/n-in-classpath-scanner branch April 23, 2026 08:24
@github-project-automation github-project-automation Bot moved this from In Progress to Done in OpenRewrite Apr 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

1 participant