Repository navigation
Fix schemagen failing at random in parallel builds - #476
Open
udengaardandersent-ELS wants to merge 1 commit into
Open
udengaardandersent-ELS wants to merge 1 commit into
udengaardandersent-ELS wants to merge 1 commit into
Conversation
Maven gives all modules that use the plugin one shared plugin realm. Each schemagen execution adds the system tools packages to that realm with ClassRealm.importFrom, which writes to an unsynchronised TreeSet. Two executions at the same moment can corrupt the set and fail with a NullPointerException in TreeMap.rotateRight. Make the imports while holding the realm's lock. Fixes mojohaus#475 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
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.
Fixes #475.
Why
Maven gives all modules that use this plugin one shared plugin realm. Each
schemagenrun adds the system tools packages to that realm withClassRealm.importFrom. That method writes to a plainTreeSetand is not thread-safe.In a parallel build (
-T), two runs can do this at the same moment. The set gets corrupted, and the build fails at random:What changed
importSystemToolsPackages.No parameters, defaults or output change, so no documentation update is needed.
Test
AbstractXsdGeneratorMojoTest.importSystemToolsPackagesFromParallelExecutionscalls the method from two threads at once, 20,000 times. Each round uses a fresh realm, set up as Maven does it. It takes about half a second.An integration test under
src/itwould not catch this reliably. The race window is a few microseconds, and a 16-module build with-T 16passed 40 times out of 40 without the fix.mvn -P run-its verifypasses: 183 unit tests and 45 integration tests.🤖 Generated with Claude Code