Avoid NPE in XMP schema registry on threads that did not seed the containers#1604
Conversation
…ign threads Signed-off-by: Sai Asish Y <say.apm35@gmail.com>
📝 WalkthroughWalkthroughStaticXmpCoreContainers ThreadLocal maps are now auto-initialized per thread using ChangesThread-safe XMP Schema Registry
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
core/src/test/java/org/verapdf/model/impl/axl/XMPSchemaRegistryThreadTest.java (1)
52-52: ⚡ Quick winSurface the captured throwable to preserve the stack trace on failure.
If the worker thread fails,
assertEquals(null, failure.get())reports only the throwable'stoString()and discards the stack trace, making the regression harder to diagnose. Rethrowing (orfail-ing) with the captured throwable keeps full context.♻️ Proposed improvement
- assertEquals(null, failure.get()); + if (failure.get() != null) { + throw new AssertionError("Lookup on foreign thread failed", failure.get()); + } assertEquals("rdf:", prefix.get());🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@core/src/test/java/org/verapdf/model/impl/axl/XMPSchemaRegistryThreadTest.java` at line 52, The test currently calls assertEquals(null, failure.get()) which loses the original stack trace; change the assertion to rethrow or fail with the captured throwable from failure.get() in XMPSchemaRegistryThreadTest so the original stack trace is preserved (e.g., check failure.get() != null and throw or call fail with that Throwable, or wrap it in a RuntimeException while preserving the cause). Locate the failure AtomicReference/field used via failure.get() and replace the assertEquals usage with the rethrow/fail approach to preserve full context.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In
`@core/src/test/java/org/verapdf/model/impl/axl/XMPSchemaRegistryThreadTest.java`:
- Line 52: The test currently calls assertEquals(null, failure.get()) which
loses the original stack trace; change the assertion to rethrow or fail with the
captured throwable from failure.get() in XMPSchemaRegistryThreadTest so the
original stack trace is preserved (e.g., check failure.get() != null and throw
or call fail with that Throwable, or wrap it in a RuntimeException while
preserving the cause). Locate the failure AtomicReference/field used via
failure.get() and replace the assertEquals usage with the rethrow/fail approach
to preserve full context.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 8d549174-0130-4d20-9b7a-0dd12312b6dc
📒 Files selected for processing (2)
core/src/test/java/org/verapdf/model/impl/axl/XMPSchemaRegistryThreadTest.javaxmp-core/src/main/java/org/verapdf/xmp/containers/StaticXmpCoreContainers.java
|
@ SAY-5 Thank you for contribution! |
The thread-local namespace and prefix maps in StaticXmpCoreContainers are only populated by clearAllContainers(), which the XMPSchemaRegistryImpl constructor calls on the constructing thread. Any other thread, such as a virtual thread spawned after the singleton registry is built, sees a null map and getNamespacePrefix() throws a NullPointerException before it can fall back to the standard namespace map. Initialising the thread-locals with ThreadLocal.withInitial(HashMap::new) gives every thread an empty map, so lookups fall through to the standard maps as intended. Fixes #1603.
Summary by CodeRabbit
Tests
Refactor