Add TypeNameMatcher to RecipeClassLoader allowlist#7582
Merged
jkschneider merged 1 commit intomainfrom May 6, 2026
Merged
Conversation
`RecipeClassLoader.PARENT_DELEGATED_PREFIXES` includes `org.openrewrite.java.internal.TypesInUse`, ensuring the parent and child classloaders share one `TypesInUse` Class object. The signature of `TypesInUse.hasTypeMatching` was extended with a new parameter type, `org.openrewrite.java.TypeNameMatcher`, but `TypeNameMatcher` was not added to the allowlist. The result: when a recipe-loaded `UsesType.visit()` invokes `TypesInUse.hasTypeMatching(TypeNameMatcher, boolean)`, the recipe classloader resolves `TypeNameMatcher` to its own copy (from the recipe artifact's bundled rewrite-core), while the parent-loaded `TypesInUse` was compiled against the parent's `TypeNameMatcher`. The JVM enforces a loader constraint and throws `LinkageError` because the two classloaders disagree on `TypeNameMatcher`'s identity. Each error fires once per `(recipe instance, source file)` pair and writes a multi-KB stack trace to the `SourcesFileErrors` data table. On Spring-heavy multi-recipe runs this produced hundreds of MB to tens of GB per repo. Adding `TypeNameMatcher` to the allowlist forces both classloaders to resolve to the same `Class` object, satisfying the loader constraint. Validated locally with `mod` CLI: running `io.moderne.java.spring.boot4.SpringBoot4BestPractices` on a Spring-using repo dropped `SourcesFileErrors` from 111,767 rows to 4, eliminating all LinkageError occurrences.
jkschneider
approved these changes
May 6, 2026
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.
Problem
RecipeClassLoader.PARENT_DELEGATED_PREFIXESincludesorg.openrewrite.java.internal.TypesInUseso that recipes and the host (e.g. mod CLI, recipe worker) agree on a single sharedTypesInUseClass. The signature ofTypesInUse.hasTypeMatchingwas recently extended with a new parameter typeorg.openrewrite.java.TypeNameMatcher, butTypeNameMatcherwas not added to the allowlist.When a recipe-loaded
UsesType.visit()invokesTypesInUse.hasTypeMatching(TypeNameMatcher, boolean):UsesTypeis loaded by the recipe classloader, which resolvesTypeNameMatcherto its own copy from the recipe artifact's bundled rewrite-core.TypesInUseis loaded by the parent classloader, which resolvesTypeNameMatcherto the parent's copy.java.lang.LinkageErrorbecause the two classloaders disagree onTypeNameMatcher'sClassidentity.The error fires once per
(recipe instance, source file)pair, with each row writing a multi-KB stack trace to theSourcesFileErrorsdata table. On Spring-heavy runs this can produce hundreds of MB of error rows per repo.Solution
Add
org.openrewrite.java.TypeNameMatchertoPARENT_DELEGATED_PREFIXES. Both classloaders then resolveTypeNameMatchervia the parent and share a singleClassobject, satisfying the loader constraint.Validation
Validated locally:
SourcesFileErrorsrowsSourcesFileErrors.csv.gzsizeLinkageErrorrows(The 4 remaining rows are an unrelated
K.Return.getPrefix()NPE inrewrite-kotlin, not affected by this change.)The same one-line fix is also being submitted to the parallel
io.moderne.recipe.RecipeClassLoaderinmoderneinc/moderne-recipe-loading-commonsfor the v1 worker path.