fix: Prefer accessible interface methods over internal implementation classes (backport #485 to ognl-3-4-x)#503
Merged
lukaszlenart merged 1 commit intoognl-3-4-xfrom Nov 29, 2025
Conversation
a49f656 to
ebfe03f
Compare
…backport #485 to ognl-3-4-x) Fixes #286 - OGNL choosing method on unexported class rather than exported interface This backport adapts PR #485 from main branch for Java 8 compatibility: - Added isLikelyAccessible() helper method (Java 8 compatible) - Enhanced findBestMethod() tie-breaking logic to prefer accessible methods - Added comprehensive test coverage (36 new tests: 10 unit + 26 integration) Java 8 adaptations: - Use clazz.getPackage().getName() instead of getPackageName() - Remove Module API checks (Java 9+ only) - Use Arrays.asList() instead of List.of() in tests - Convert from JUnit 5 to JUnit 4 - Swap assertion parameter order (message first in JUnit 4) - Replace assertDoesNotThrow() with try-catch pattern Test results: 993 tests passed (957 existing + 36 new), 0 failures 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
ebfe03f to
fb97bb1
Compare
|
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 backports #485 from the main branch (Java 17+) to the ognl-3-4-x branch (Java 8 compatible).
Fixes: #286 - OGNL choosing method on unexported class rather than exported interface
Problem:
When calling methods on objects, OGNL was selecting methods from internal JDK implementation classes (e.g.,
sun.security.x509.X509CertImpl) instead of the public interface (java.security.cert.X509Certificate). This causesIllegalAccessExceptionbecause the Java module system doesn't export internal packages.Solution:
isLikelyAccessible()helper method to detect potentially inaccessible classesfindBestMethod()tie-breaking logic to prefer accessible methods over internal onesChanges
Production Code (1 file modified):
src/main/java/ognl/OgnlRuntime.javaisLikelyAccessible()method (45 lines, package-private for testing)findBestMethod()tie-breaking logic (20 lines)Test Files (6 files created):
src/test/java/sun/test/PublicTestInterface.java- Test helper interfacesrc/test/java/sun/test/SimulatedInternalClass.java- Simulates internal sun.* classsrc/test/java/com/sun/test/AnotherInternalClass.java- Tests com.sun.* detectionsrc/test/java/ognl/OgnlRuntimeAccessibilityTest.java- 10 unit tests for isLikelyAccessible()src/test/java/ognl/test/Issue286Test.java- 26 integration tests for the fixJava 8 Adaptations
This backport required several adaptations from the original PR #485 to maintain Java 8 compatibility:
API Changes:
clazz.getPackageName()→clazz.getPackage().getName()(getPackageName() is Java 9+)Test Framework:
classtopublic classvoid method()topublic void method()assertDoesNotThrow()with try-catch pattern (doesn't exist in JUnit 4)Java 8 API:
List.of()→Arrays.asList()(List.of() is Java 9+)import java.util.Arrays;Test Results
All 993 tests pass (957 existing + 36 new):
Backward Compatibility
✅ Fully backward compatible
References
Test Plan
🤖 Generated with Claude Code