[GEODE-10519] Security : Remove Unsafe Reflection Breaking Java Module System Encapsulation#7954
Merged
JinwooHwang merged 3 commits intoapache:developfrom Dec 4, 2025
Merged
Conversation
…ation - Removed reflection access to ThreadLocal/ThreadLocalMap internals - Implemented cross-thread value lookup using synchronized WeakHashMap - Removed requirement for --add-opens=java.base/java.lang=ALL-UNNAMED - WeakHashMap ensures terminated threads can be garbage collected - Maintains same API and functionality for deadlock detection - All existing tests pass without JVM flag changes This eliminates the fragile reflection-based approach that required special JVM flags and was vulnerable to Java module system changes. The new implementation is safer, more maintainable, and works across all Java versions without requiring internal access.
- Removed unnecessary JVM flag from geode-test.gradle line 185 - Flag no longer needed after UnsafeThreadLocal refactoring - Tests now run with same security constraints as production - All UnsafeThreadLocal and deadlock tests pass without the flag - Validates that refactoring truly eliminated reflection dependency
Contributor
Author
|
All tests have passed. Thank you for your support @sboorlagadda |
6 tasks
Contributor
Author
|
We are ready to merge. Please let me know if you have any concerns. Thank you very much for your support. |
Contributor
Author
|
Thank you so much for your support @sboorlagadda |
JinwooHwang
added a commit
that referenced
this pull request
Dec 8, 2025
…e System Encapsulation (#7954) * Replace reflection-based UnsafeThreadLocal with WeakHashMap implementation - Removed reflection access to ThreadLocal/ThreadLocalMap internals - Implemented cross-thread value lookup using synchronized WeakHashMap - Removed requirement for --add-opens=java.base/java.lang=ALL-UNNAMED - WeakHashMap ensures terminated threads can be garbage collected - Maintains same API and functionality for deadlock detection - All existing tests pass without JVM flag changes This eliminates the fragile reflection-based approach that required special JVM flags and was vulnerable to Java module system changes. The new implementation is safer, more maintainable, and works across all Java versions without requiring internal access. * Remove --add-opens=java.base/java.lang from test configuration - Removed unnecessary JVM flag from geode-test.gradle line 185 - Flag no longer needed after UnsafeThreadLocal refactoring - Tests now run with same security constraints as production - All UnsafeThreadLocal and deadlock tests pass without the flag - Validates that refactoring truly eliminated reflection dependency
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.
Summary
This PR eliminates reflection-based access to private
java.langinternals inUnsafeThreadLocal, removing the requirement for the--add-opens=java.base/java.lang=ALL-UNNAMEDJVM flag. The refactoring replaces the fragile reflection approach with aWeakHashMap-based implementation that is safer, more maintainable, and fully compliant with the Java Platform Module System (JPMS).Security & Compliance Benefits
Module System Compliance
--add-opensflagsSecurity Hardening
java.langpackage to all modulesOperational Benefits
Technical Changes
Files Modified (3 files, 49 insertions(+), 59 deletions(-))
1. geode-core/src/main/java/.../deadlock/UnsafeThreadLocal.java (100 lines changed)
Before: Used reflection to access private ThreadLocal internals
After: Uses WeakHashMap to track thread-to-value mappings
Key improvements:
invokePrivate,getPrivatemethods)WeakHashMap<Thread, T>for cross-thread accessset()andremove()to maintain WeakHashMap consistencyget(Thread)to use map lookup instead of reflection2. geode-gfsh/src/main/java/.../commands/MemberJvmOptions.java (6 lines deleted)
JAVA_LANG_OPENconstant and importJAVA_11_OPTIONSlist from 5 to 4 flags--add-opens=java.base/java.lang=ALL-UNNAMED3. build-tools/scripts/src/main/groovy/geode-test.gradle (1 line changed)
--add-opens=java.base/java.lang=ALL-UNNAMEDfrom test JVM argsArchitecture Decision
Why WeakHashMap?
Collections.synchronizedMap()Why not alternatives?
Validation & Testing
Test Coverage
Backward Compatibility
Public API preserved - No changes to method signatures
Behavior unchanged - Functionally equivalent to reflection-based approach
Consumer files unchanged - DLockService, MessageDependencyMonitor, DLockDependencyMonitor require no modifications
Deadlock detection accuracy - No regression in detection or timing
Impact Analysis
No Changes Required For
These files use
UnsafeThreadLocalbut required zero modifications because the public API was preserved:This demonstrates successful encapsulation - internal implementation changed while external contract remained stable.
Performance Considerations
Maintenance Benefits
Related Work
Future Opportunities
This PR is part of a broader initiative to eliminate reflection-based access across Geode:
--add-opens=java.base/java.nio=ALL-UNNAMEDJava Version Support
Checklist
Acceptance Criteria (All Met)
Additional Context
Why This Matters
java.langpackage with--add-opensweakens module boundariesHistorical Context
The original
UnsafeThreadLocalimplementation was created when Java module system didn't exist. With modern Java (11+), the JPMS violations became problematic:--add-opensflagsThis refactoring modernizes the implementation while maintaining all functionality.
Total changes: 3 files, 49 insertions(+), 59 deletions(-), ~66% code rewrite
For all changes, please confirm:
develop)?gradlew buildrun cleanly?