Skip to content

Resolve record component accessors in property access - #415

Merged
henrib merged 1 commit into
apache:masterfrom
murdos:record-accessor-support
Sep 14, 2026
Merged

henrib merged 1 commit into
apache:masterfrom
murdos:record-accessor-support

Conversation

@murdos

@murdos murdos commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

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.

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.
@henrib

henrib commented Sep 14, 2026

Copy link
Copy Markdown
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.
I refactored very little : moved the reflection logic into ClassTool, updated the test to use test permissions.
Thanks again for improving JEXL.

@henrib
henrib merged commit 2b997c1 into apache:master Sep 14, 2026
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants