refactor: change null-safe operator syntax from .? to ?.#496
Merged
lukaszlenart merged 3 commits intomainfrom Nov 18, 2025
Merged
refactor: change null-safe operator syntax from .? to ?.#496lukaszlenart merged 3 commits intomainfrom
lukaszlenart merged 3 commits intomainfrom
Conversation
Changes the null-safe navigation operator from ".?" to "?." to align with industry-standard syntax used by Kotlin, TypeScript, C#, and Groovy. This improves consistency across programming languages and provides a more familiar syntax for developers coming from other ecosystems. Updated components: - Grammar definition in ognl.jj (token and production rules) - ASTChain implementation (JavaDoc and toString method) - All null-safe operator tests (4 test files) - Documentation (NullSafeOperator.md and LanguageGuide.md) - Updated rationale to emphasize language consistency All 683 tests pass with the new syntax. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Extracted nested condition into shouldAppendNavigationOperator() helper method to reduce cognitive complexity from 17 to below the threshold of 15. This addresses the SonarCloud code smell (java:S3776) by improving code readability and reducing the nesting level in the toString() method. Changes: - Extract complex condition into private helper method - Simplify nested if statement with single condition check - Maintain identical behavior while improving maintainability All 683 tests pass. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Added comprehensive SonarCloud documentation including: - Project key and URLs - How to view PR-specific issues - Available MCP tools for SonarCloud integration - Common SonarCloud rules encountered in OGNL - Best practices for addressing quality issues This helps future development by providing clear guidance on: 1. Using SonarQube MCP tools to fetch and address issues 2. Understanding common code smells specific to this project 3. Following quality gate requirements for PRs 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
|
lukaszlenart
added a commit
that referenced
this pull request
Nov 18, 2025
Add SAFE_DOT token and modify navigationChain production rule to support null-safe navigation syntax (user?.profile?.city). The parser now recognizes the ?. operator and sets a nullSafe flag on ASTChain nodes, enabling null-safe property navigation that returns null instead of throwing exceptions when encountering null intermediate values. Ported from main branch PRs #484 and #496. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
lukaszlenart
added a commit
that referenced
this pull request
Nov 18, 2025
Add nullSafe field and null-checking logic in getValueBody().
Returns null when encountering null intermediate values instead
of throwing exceptions.
Update toString() to output ?. operator when nullSafe flag is set.
Add helper method shouldAppendNavigationOperator() to reduce
cognitive complexity.
This enables expressions like:
- user?.profile?.city (returns null if any part is null)
- items?.{? #this > 0} (null-safe collection operations)
- #var?.method() (null-safe method calls)
Ported from main branch PRs #484 and #496, adapted for Java 8
compatibility (ognl-3-4-x branch).
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>
7 tasks
lukaszlenart
added a commit
that referenced
this pull request
Nov 29, 2025
…#497) * feat(parser): add null-safe navigation operator (?.) token support Add SAFE_DOT token and modify navigationChain production rule to support null-safe navigation syntax (user?.profile?.city). The parser now recognizes the ?. operator and sets a nullSafe flag on ASTChain nodes, enabling null-safe property navigation that returns null instead of throwing exceptions when encountering null intermediate values. Ported from main branch PRs #484 and #496. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * feat(core): implement null-safe operator logic in ASTChain Add nullSafe field and null-checking logic in getValueBody(). Returns null when encountering null intermediate values instead of throwing exceptions. Update toString() to output ?. operator when nullSafe flag is set. Add helper method shouldAppendNavigationOperator() to reduce cognitive complexity. This enables expressions like: - user?.profile?.city (returns null if any part is null) - items?.{? #this > 0} (null-safe collection operations) - #var?.method() (null-safe method calls) Ported from main branch PRs #484 and #496, adapted for Java 8 compatibility (ognl-3-4-x branch). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> --------- Co-authored-by: Claude <[email protected]>
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.




Summary
Changes the null-safe navigation operator syntax from
.?to?.to align with industry-standard syntax used by Kotlin, TypeScript, C#, and Groovy.Motivation
The original implementation used
.?(dot-question) to differentiate OGNL from other languages. However, using?.(question-dot) provides better consistency across the programming ecosystem and a more familiar syntax for developers coming from other languages.Changes
Grammar & Implementation
< SAFE_DOT: ".?" >to< SAFE_DOT: "?." >ASTChain.javaJavaDoc andtoString()method to reflect new syntax?.operatorTests
All test files updated with new syntax:
NullSafeOperatorTest.java(~65 test expressions)NullSafeIntegrationTest.java(integration tests)NullSafeCompilationTest.java(compilation tests)NullSafeCollectionTest.java(collection tests)Documentation
docs/NullSafeOperator.md(title, rationale, all examples)docs/LanguageGuide.md(null-safe operator section)Test Results
All 683 tests pass successfully with the new syntax:
Breaking Change
.?operator from PR #484Users will need to update their OGNL expressions from
.?to?.when upgrading.Before:
After:
Files Changed
8 files modified, 154 insertions(+), 154 deletions(-):
ognl/src/main/javacc/ognl.jjognl/src/main/java/ognl/ASTChain.java🤖 Generated with Claude Code