Skip to content

Fix Issue #472: Preserve root context in nested evaluations (port from PR #476)#483

Merged
lukaszlenart merged 1 commit intomainfrom
fix/issue-472-root-context-preservation
Nov 7, 2025
Merged

Fix Issue #472: Preserve root context in nested evaluations (port from PR #476)#483
lukaszlenart merged 1 commit intomainfrom
fix/issue-472-root-context-preservation

Conversation

@lukaszlenart
Copy link
Copy Markdown
Collaborator

Summary

Ports the fix from PR #476 (ognl-3-4-x branch) to the main branch with adaptations for backward compatibility. This fix resolves Issue #472 where lambda expressions in list operations (selection, projection) cannot access properties from the original context root via #root references.

Root Cause

Ognl.getValue() unconditionally called context.withRoot(root) which overwrote the context root during nested evaluations. When processing list items in lambda expressions, this caused #root to reference the current list item instead of the original context root, making original root properties inaccessible.

Solution

Implemented conditional root preservation logic that only updates the context root when:

  1. Context has no root yet (initial evaluation), OR
  2. Root is the same as context root (not a nested call), OR
  3. Context is empty (no user variables)

This prevents nested evaluations from overwriting the original root while maintaining backward compatibility for existing use cases.

Changes

  • Modified ognl/src/main/java/ognl/Ognl.java: Added smart conditional logic to preserve root context during nested evaluations
  • Added ognl/src/test/java/ognl/test/Issue472CustomMethodAccessorTest.java: Comprehensive test suite with 5 test cases validating root preservation

Test Coverage

New Issue472CustomMethodAccessorTest validates:

  • ✅ List selection can access root properties via #root.property
  • ✅ Empty results when root property doesn't match
  • ✅ Both #root and #this work correctly in lambda expressions
  • ✅ Multiple root properties accessible in single expression
  • ✅ List projection preserves root access

Verification

Differences from PR #476

Aspect PR #476 (ognl-3-4-x) This PR (main)
Approach Removed context update entirely Conditional context update
Compatibility Breaking change (null throws exceptions) Fully backward compatible
Short-circuit Removed feature Preserved feature
Tests Updated existing tests All existing tests unchanged

Test Results

[INFO] Tests run: 612, Failures: 0, Errors: 0, Skipped: 0

Fixes #472

🤖 Generated with Claude Code

@lukaszlenart lukaszlenart force-pushed the fix/issue-472-root-context-preservation branch 2 times, most recently from c9260e3 to 9c0606b Compare November 7, 2025 13:37
Port fix from PR #476 (ognl-3-4-x) to main branch with adaptations for
backward compatibility. Lambda expressions in list operations (selection,
projection) can now access properties from the original context root via
#root references.

Root cause: Ognl.getValue() called context.withRoot(root) which overwrote
the context root during nested evaluations (e.g., when processing list items),
making original root properties inaccessible.

Solution: Conditionally preserve original root by only calling withRoot()
when context has no root, root matches existing root, or context is empty.
This maintains backward compatibility while fixing #root access in lambdas.

Changes:
- Modified Ognl.getValue() to preserve root context during nested evaluations
- Added Issue472CustomMethodAccessorTest with 5 comprehensive test cases
- All 612 existing tests pass, maintaining backward compatibility
- Short-circuit optimization preserved (not removed like in PR #476)

Fixes #472

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@lukaszlenart lukaszlenart force-pushed the fix/issue-472-root-context-preservation branch from 9c0606b to b632d11 Compare November 7, 2025 13:51
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Nov 7, 2025

@lukaszlenart lukaszlenart merged commit 4762a52 into main Nov 7, 2025
5 checks passed
@lukaszlenart lukaszlenart deleted the fix/issue-472-root-context-preservation branch November 7, 2025 14:29
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.

ognl 3.4.8 - root properties not accessible from lambda

1 participant