Fix #44268: Prevent NoSuchElementException in TOML parser endMode()#44306
Open
DuraCode2003 wants to merge 1 commit intoballerina-platform:masterfrom
Open
Fix #44268: Prevent NoSuchElementException in TOML parser endMode()#44306DuraCode2003 wants to merge 1 commit intoballerina-platform:masterfrom
DuraCode2003 wants to merge 1 commit intoballerina-platform:masterfrom
Conversation
- Add isEmpty() checks before modeStack.pop() and modeStack.peek() - Prevents stack underflow during TOML parsing error recovery - Handles malformed TOML files with invalid escape sequences gracefully Fixes ballerina-platform#44268
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #44306 +/- ##
============================================
- Coverage 75.08% 75.08% -0.01%
+ Complexity 58490 58489 -1
============================================
Files 3595 3595
Lines 225855 225857 +2
Branches 29342 29343 +1
============================================
- Hits 169588 169584 -4
- Misses 46866 46871 +5
- Partials 9401 9402 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
Purpose
Fixes #44268 - The TOML parser crashes with
NoSuchElementExceptionwhen parsing malformed TOML files containing invalid escape sequences. The crash occurs inAbstractLexer.endMode()when the mode stack becomes empty during error recovery.Fixes #44268
Approach
Added defensive programming checks to
AbstractLexer.endMode():modeStack.isEmpty()before callingpop()modeStack.isEmpty()before callingpeek()after poppingThe fix prevents stack underflow while allowing the parser to continue error recovery gracefully.
Samples
Before the fix, malformed TOML like
key = "\z invalid"would crash with:java.util.NoSuchElementException
at java.base/java.util.ArrayDeque.pop(ArrayDeque.java:547)
at io.ballerina.toml.internal.parser.AbstractLexer.endMode(AbstractLexer.java:102)
After the fix, the same input is handled gracefully as a parsing error without crashing.
Remarks
Check List