-
Notifications
You must be signed in to change notification settings - Fork 121
Fix NullPointerException in incomplete ternary operator parsing #3723
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix NullPointerException in incomplete ternary operator parsing #3723
Conversation
|
Important Review skippedBot user detected. To trigger a single review, invoke the You can disable this status message by setting the Comment |
…ete ternary operators Co-authored-by: nixel2007 <[email protected]>
…erator Co-authored-by: nixel2007 <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR fixes a NullPointerException that occurs when parsing incomplete ternary operators in BSL code (e.g., when a user types Возврат ? or just ?). The fix adds defensive null checks at two key points in the expression tree building process to prevent crashes and instead create error nodes for graceful error handling.
Key changes:
- Added null guard in
buildExpressionTreeto return null early when expression context is null - Modified
visitTernaryOperatorto check for null sub-expressions and createErrorExpressionNodeinstead of crashing with NPE - Added test coverage for incomplete ternary operator parsing
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| ExpressionTreeBuildingVisitor.java | Added null safety checks in buildExpressionTree (early return) and visitTernaryOperator (error node creation) to prevent NPE when parsing incomplete ternary operators |
| ExpressionTreeBuildingVisitorTest.java | Added test case for incomplete ternary operator scenario to verify error handling works correctly without throwing exceptions |
The implementation follows the existing error handling patterns in the codebase by using ErrorExpressionNode for malformed expressions, consistent with how other error cases are handled throughout the visitor (e.g., in visitNewExpression, visitParenthesis, visitMember). The fix is minimal, targeted, and maintains backward compatibility while preventing crashes during live editing scenarios.
Test Results 312 files - 2 496 312 suites - 2 496 9m 59s ⏱️ - 43m 36s Results for commit d6e3e22. ± Comparison against base commit e5b5781. This pull request removes 8 and adds 5 tests. Note that renamed tests count towards both. |
|



The expression tree builder crashes when parsing incomplete ternary operators (e.g.,
Возврат ?) because it attempts to dereference null expression contexts.Changes
buildExpressionTree: Add null guard to return early instead of passing null tovisitExpressionvisitTernaryOperator: Check for null sub-expressions and createErrorExpressionNodeinstead of callingObjects.requireNonNullExample
The fix maintains consistency with existing error handling patterns by treating incomplete ternary operators as error expressions rather than failing hard.
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.