Skip to content

JEXL-477: Parse interpolation strings with the features of their script - #427

Merged
henrib merged 4 commits into
masterfrom
JEXL-477
Nov 19, 2026
Merged

henrib merged 4 commits into
masterfrom
JEXL-477

Conversation

@henrib

@henrib henrib commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

JEXL-477. Stacked on #425 (JEXL-476); the base branch is JEXL-476 so that only this change shows.

Problem

The expressions embedded in an interpolation string (`${...}`, `#{...}`) or in an interpolated property name (x.`${...}`) were parsed with the features of the engine, not with those of the script that contains them. This only shows when a script is created with its own features through JexlEngine.createScript(JexlFeatures, JexlInfo, String, String...):

  • engine allowing method calls, script created with methodCall(false): s.length() is rejected but `${s.length()}` evaluated as 3;
  • conversely, with a restrictive engine and a permissive script, the call was accepted directly and rejected inside the interpolation;
  • antish names declared by the features of the script (JEXL-474) were not solved inside interpolations: x.y evaluated but `${x.y}` failed.

Fix

The parser hands its current features to the interpolation it creates (Parser.jjt, ASTJxltLiteral, ASTIdentifierAccessJxlt, JexlParser.parseInterpolation). TemplateEngine.createExpression derives the expression features from them, uses them to parse and as part of the cache key, and nested expressions keep them for their deferred parse. Scripts created with the features of the engine are not affected. All signature changes are in the parser and internal packages.

Tests

JxltFeatureEnforcementTest.testInterpolationHonorsScriptFeatures (both directions, including the cached expression) and testInterpolationHonorsDeclaredAntish.

🤖 Generated with Claude Code

The expressions embedded in an interpolation string or an interpolated
property name were parsed with the features of the engine. The parser
now hands its current features to the interpolation it creates, so that
a script created with its own features has them enforced, and its
declared antish names solved, inside interpolations; cached interpolation
expressions are keyed by those features.

Co-Authored-By: Claude <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings November 12, 2026 14:19

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

4 open issues
What changed in this PR

This PR fixes JEXL-477 by ensuring expressions embedded in interpolations (template literals and interpolated property names) are parsed using the containing script’s JexlFeatures, not the engine’s.

Changes:

  • Pass the current parser/script features through AST nodes and into interpolation parsing.
  • Update TemplateEngine expression creation/caching to derive features from the embedded script and include them in cache keys and deferred parses.
  • Add regression tests validating feature enforcement (method calls + declared antish names) in interpolations.
File Description
src/​test/​java/​org/​apache/​commons/​jexl3/​JxltFeatureEnforcementTest.java Adds regression tests ensuring interpolations honor script-level features (including caching and antish names).
src/​main/​java/​org/​apache/​commons/​jexl3/​parser/​Parser.jjt Propagates current parsing features into Jxlt literal and identifier-access interpolation nodes.
src/​main/​java/​org/​apache/​commons/​jexl3/​parser/​JexlParser.java Extends interpolation parsing API to accept script features and forwards them into TemplateEngine.
src/​main/​java/​org/​apache/​commons/​jexl3/​parser/​ASTJxltLiteral.java Stores interpolation expressions created with the script’s features.
src/​main/​java/​org/​apache/​commons/​jexl3/​parser/​ASTIdentifierAccessJxlt.java Ensures interpolated identifier access is parsed with the script’s features.
src/​main/​java/​org/​apache/​commons/​jexl3/​internal/​TemplateEngine.java Derives/normalizes expression features from embedded script features and includes them in caching + nested parsing.
src/​main/​java/​org/​apache/​commons/​jexl3/​internal/​Engine.java Adds an overload to parse with explicit JexlFeatures and routes existing calls through it.
src/​changes/​changes.xml Adds a changelog entry for JEXL-477.

Review effort: Lite

Comment thread src/changes/changes.xml Resolved
…error message

Address review comments.

Co-Authored-By: Claude <noreply@anthropic.com>
…rcing GC

The loop that fills the heap to force a GC relies on the JVM clearing
soft references rather than failing an allocation; on Java 27 (Windows),
the allocation failed. Catch the error, release the big objects and
carry on.

Co-Authored-By: Claude <noreply@anthropic.com>
@henrib
henrib requested a balanced review from Copilot November 13, 2026 12:56

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread src/changes/changes.xml
<body>
<release version="3.7.2" date="YYYY-MM-DD" description="This is a feature and maintenance release. Java 8 or later is required.">
<!-- FIX -->
<action dev="henrib" due-to="Claude" type="fix" issue="JEXL-477">Interpolation strings are parsed with the engine features instead of those of their script.</action>

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kept as is, same as the earlier thread: in this file, fix entries state the problem as the JIRA title does.

Comment on lines +380 to 393
try {
for (int b = 0; b < 1024 && Runtime.getRuntime().freeMemory() > MEGA; ++b) {
final BigObject big = new BigObject(b);
stuff.add(new InstanceReference(big, queue));
}
} catch (final OutOfMemoryError oom) {
// exhausting the heap is the intent; if the JVM fails an allocation instead of
// clearing the soft references, release the big objects and carry on
for (final Reference<?> soft : stuff) {
if (soft instanceof InstanceReference) {
soft.clear();
}
}
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kept as is: what the test asserts is unchanged, a generated class must be collected and reloaded (gced >= 0, second pass). Filling the heap is only a means to provoke a GC, and the clearing of soft references is the JVM's business, not what is under test.

Comment on lines +1018 to +1023
private JexlFeatures features(final JexlFeatures ftrs) {
if (ftrs == null) {
return noscript ? jexl.expressionFeatures : jexl.scriptFeatures;
}
return noscript && ftrs.supportsScript() ? new JexlFeatures(ftrs).script(false) : ftrs;
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a hot path: the features are derived when the parser builds an interpolation node, once per node, and evaluation uses the expression stored in the node. Still, scripts created with the features of the engine did not need a copy before this change; e0f00f2 reuses the engine expression features for them, so only scripts created with their own features derive one.

…engine scripts

Only derive expression features when a script was created with its own
features; a script created with the features of the engine parses its
interpolations with the engine expression features, as before.

Co-Authored-By: Claude <noreply@anthropic.com>
Base automatically changed from JEXL-476 to master November 19, 2026 07:14
@henrib
henrib merged commit 7f421c8 into master Nov 19, 2026
14 checks passed
@henrib
henrib deleted the JEXL-477 branch November 19, 2026 07:15
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