Resolve record component accessors in property access - #415
Merged
Merged
Conversation
foo.bar never resolved to a record's generated bar() accessor, only to getBar()/isBar(), a public field, or duck-typed get(Object). Add a RecordGetExecutor that matches property to record component and lets Introspector resolve the actual accessor Method, so it still goes through the usual permission checks. Detection is done entirely via reflection (Class#isRecord(), Class#getRecordComponents()) since this module still targets Java 8; on such a runtime these methods simply don't exist and discovery quietly reports no match. The new test compiles its record fixtures on the fly with javax.tools.JavaCompiler and skips itself below Java 16, since 'record' isn't valid syntax at this module's source level either.
henrib
added a commit
that referenced
this pull request
Sep 14, 2026
- Builds on the record accessor support originally proposed by Aurelien Mino in #415. - Move the Class#isRecord()/getRecordComponents() reflection out of RecordGetExecutor and into the existing ClassTool backport utility, resolved via MethodHandle to match how it already backports Java 9+ module reflection, instead of duplicating a separate Method-based lookup. - Fix RecordPropertyAccessTest's on-the-fly compiled record fixture to actually compile into org.apache.commons.jexl3. Also switch the test to extend JexlTestCase and use the shared restricted-permissions engine instead of a bespoke UNRESTRICTED-permissions one, matching the rest of the suite. - Correct @SInCE on the namespaceInstantiation additions (JexlFeatures, JexlOptions) from stale 3.6 to 3.7.1, and RecordGetExecutor from 3.7.2 to 3.7.1, matching the actual in-flight version. - Reorder actions within each changes.xml section by descending JEXL issue number.
Contributor
|
Thanks a lot for your contribution Aurélien; I've ported your improvement to https://github.com/apache/commons-jexl/tree/JEXL-472 (and created the corresponding Jira issue) to expedite the process. |
pull Bot
pushed a commit
to Mu-L/commons-jexl
that referenced
this pull request
Sep 14, 2026
…ture Move the Class#isRecord()/getRecordComponents() reflection out of RecordGetExecutor and into the existing ClassTool backport utility, resolved via MethodHandle to match how it already backports Java 9+ module reflection, instead of duplicating a separate Method-based lookup. Fix RecordPropertyAccessTest's on-the-fly compiled record fixture to actually compile into org.apache.commons.jexl3 (it previously compiled with no package, then looked itself up under that package, which does not resolve). Also switch the test to extend JexlTestCase and use the shared restricted-permissions engine instead of a bespoke UNRESTRICTED-permissions one, matching the rest of the suite. Builds on the record accessor support originally proposed by Aurelien Mino in apache#415. Co-Authored-By: Claude Code <noreply@anthropic.com>
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.
Property access (`foo.bar`) never resolves to a record's generated `bar()` accessor, only to `getBar()`/`isBar()`, a public field, or a duck-typed `get(Object)`. `point.x` on a record `Point(int x, int y)` throws `JexlException$Property: undefined property 'x'` today (or silently evaluates to null with `strict(false)`), and the only workaround is adding a manual bean-style getter on the record, which defeats the point of using one.
This adds a `RecordGetExecutor`, tried right after the existing `PropertyGetExecutor`/`BooleanGetExecutor` so a record that already defines its own `getFoo()` keeps behaving exactly as before. It matches the property name against the class's record components, then resolves the actual accessor `Method` through the existing (permission-checked) `Introspector`, so record accessors go through the same sandboxing as every other property access.
Detection and lookup use reflection only (`Class#isRecord()`, `Class#getRecordComponents()`, looked up once and cached) rather than compiling against these APIs directly, since the module still targets Java 8 - on such a runtime the lookup just fails to find the methods and quietly reports no match, same as it does today.
The test compiles its record fixtures on the fly with `javax.tools.JavaCompiler` and skips itself below Java 16, for the same reason: `record` isn't valid source at this module's language level.
No JIRA ticket yet - happy to open one if that's preferred before this gets reviewed.