Skip to content

JEXL-474: Declare antish variable names at parse time through JexlFeatures - #424

Merged
henrib merged 2 commits into
masterfrom
JEXL-474
Nov 11, 2026
Merged

henrib merged 2 commits into
masterfrom
JEXL-474

Conversation

@henrib

@henrib henrib commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

JEXL-474, stacked on #423 (JEXL-475).

Antish variables (dotted global names like x.y.z) can now be declared at parse time:

JexlFeatures features = JexlFeatures.createDefault()
    .antishTest(JexlFeatures.namePatterns(Arrays.asList("x.y", "build.*")));
  • the parser rewrites references rooted on a global so the longest declared dotted prefix is a single
    variable (x.y.z → variable x.y, property .z); local roots, ?. and back-quoted segments stop the rewrite
  • a script parsed with declared names does not solve antish variables at runtime (whatever JexlOptions.setAntish)
  • with sideEffectGlobal(false) and declared names, only assigning a global (x = 1, declared x.y = 1) is
    rejected; assigning a property of a global value (x.y.z = 1) is allowed
  • JexlFeatures.namePatterns(Collection); pragmaPatterns delegates to it
  • Interpreter: pushBlock/popBlock and AntishName helpers; fixes a null local root being solved as an
    antish variable on read (not on assign) and a lexical frame leak when a for-loop initializer throws

Declared antish variables: ~10 µs/op vs ~41 µs/op with runtime resolution (JMH InterpreterBenchmark,
mvn clean test -Pbenchmark -Dbenchmark=InterpreterBenchmark). Without a declared predicate, behavior is unchanged.

Tests: AntishFeaturesTest, InterpreterCharacterizationTest, additions to AntishCallTest.

  • mvn default goal passes
  • AI disclosure: written with Claude Code (Claude Opus 5.5), reviewed by the committer.

🤖 Generated with Claude Code

…tures

- JexlFeatures.antishTest(Predicate): the parser rewrites references rooted on a global so that
  the longest declared dotted prefix is a single variable; a script parsed with declared names
  does not solve antish variables at runtime
- with sideEffectGlobal(false) and declared names, assigning a property of a global value is not
  a global side effect
- JexlFeatures.namePatterns(Collection), pragmaPatterns delegates to it
- Interpreter: pushBlock/popBlock helpers, AntishName helper for runtime antish resolution
- fix: a null local variable root is never solved as an antish variable (read was, assign was not)
- fix: for-loop lexical frame leaked when an initializer throws
- tests: AntishFeaturesTest, InterpreterCharacterizationTest; JMH InterpreterBenchmark (pom: jmh test deps)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings November 10, 2026 15:06
Base automatically changed from JEXL-475 to master November 10, 2026 15:16

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.

🟡 Changes recommended

Null-root safe navigation regresses, and declared dotted names fail to resolve in direct calls and interpolated expressions.

3 open issues
What changed in this PR

Adds parse-time declarations for dotted global variables in JEXL, replacing runtime name resolution for scripts using the new feature.

Changes:

  • Adds antishTest and reusable name-pattern predicates, with parser rewriting and updated global-assignment checks.
  • Refactors interpreter name resolution and lexical-frame handling, including local-shadowing and loop-initializer fixes.
  • Adds regression tests, characterization coverage, and JMH benchmarks.
File Description
src/​test/​java/​org/​apache/​commons/​jexl3/​InterpreterCharacterizationTest.java Captures loop, scope, and antish behavior.
src/​test/​java/​org/​apache/​commons/​jexl3/​benchmark/​InterpreterBenchmark.java Benchmarks interpreter operations and antish resolution.
src/​test/​java/​org/​apache/​commons/​jexl3/​AntishFeaturesTest.java Tests declared names and feature interactions.
src/​test/​java/​org/​apache/​commons/​jexl3/​AntishCallTest.java Tests null-local shadowing of dotted globals.
src/​main/​java/​org/​apache/​commons/​jexl3/​parser/​SimpleNode.java Clarifies child-replacement usage in a comment.
src/​main/​java/​org/​apache/​commons/​jexl3/​parser/​Parser.jjt Adds parser-stack node replacement support.
src/​main/​java/​org/​apache/​commons/​jexl3/​parser/​JexlParser.java Rewrites declared dotted prefixes as identifiers.
src/​main/​java/​org/​apache/​commons/​jexl3/​parser/​FeatureController.java Distinguishes global assignments from property writes.
src/​main/​java/​org/​apache/​commons/​jexl3/​JexlFeatures.java Exposes declarations and reusable name predicates.
src/​main/​java/​org/​apache/​commons/​jexl3/​internal/​Interpreter.java Refactors antish resolution and lexical-frame cleanup.
src/​main/​java/​org/​apache/​commons/​jexl3/​internal/​Engine.java Disables runtime antish resolution for declared names.
src/​changes/​changes.xml Records the JEXL-474 addition.
pom.xml Adds JMH test dependencies.

Review effort: Balanced

… Debugger fixes

- a method name may complete a declared antish variable, which is then
  called as a functor, as in f.g(42);
- safe navigation: only the access applied to null decides; a.b?.c fails
  when a is null, x?.y().z fails when x.y() is null;
- the safe option also covers array accesses;
- a null local variable is reported as null, not undefined;
- for loops with an empty body or multiple declarations;
- Debugger: expression-bodied loops, lambda expressions and curried calls.

Co-Authored-By: Claude <noreply@anthropic.com>
@henrib
henrib merged commit 73ec1df into master Nov 11, 2026
16 checks passed
@henrib
henrib deleted the JEXL-474 branch November 11, 2026 17:49
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