From 749d32105462ab95380d4af3863d68b371341441 Mon Sep 17 00:00:00 2001 From: Duranka Kalpana <155367493+DuraCode2003@users.noreply.github.com> Date: Wed, 24 Sep 2025 00:23:36 +0530 Subject: [PATCH] Fix NoSuchElementException in AbstractLexer.endMode() - 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 #44268 --- .../io/ballerina/toml/internal/parser/AbstractLexer.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/misc/toml-parser/src/main/java/io/ballerina/toml/internal/parser/AbstractLexer.java b/misc/toml-parser/src/main/java/io/ballerina/toml/internal/parser/AbstractLexer.java index 0f2e0b5a2089..481af21868da 100644 --- a/misc/toml-parser/src/main/java/io/ballerina/toml/internal/parser/AbstractLexer.java +++ b/misc/toml-parser/src/main/java/io/ballerina/toml/internal/parser/AbstractLexer.java @@ -99,8 +99,12 @@ public void switchMode(ParserMode mode) { * End the current mode the mode of the lexer and fall back the previous mode. */ public void endMode() { - this.modeStack.pop(); - this.mode = this.modeStack.peek(); + if (!this.modeStack.isEmpty()) { + this.modeStack.pop(); + if (!this.modeStack.isEmpty()) { + this.mode = this.modeStack.peek(); + } + } } private void resetDiagnosticList() {