< prev index next >

src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java

Print this page
rev 60625 : 8237041: AssertionError in parsing
Summary: Avoid parser crash for deeply nested classes without closing braces, improve error recovery for classes without an opening brace.
Reviewed-by: TBD

@@ -442,11 +442,11 @@
             } else {
                 log.error(DiagnosticFlag.SYNTAX, diagPos, errorKey);
             }
         }
         S.errPos(pos);
-        if (token.pos == errorPos) {
+        if (token.pos == errorPos && token.kind != EOF) {
             //check for a possible infinite loop in parsing:
             Assert.check(count++ < RECOVERY_THRESHOLD);
         } else {
             count = 0;
             errorPos = token.pos;

@@ -4046,10 +4046,12 @@
         if (token.pos <= endPosTable.errorEndPos) {
             // error recovery
             skip(false, true, false, false);
             if (token.kind == LBRACE)
                 nextToken();
+            else
+                return List.nil();
         }
         ListBuffer<JCTree> defs = new ListBuffer<>();
         while (token.kind != RBRACE && token.kind != EOF) {
             defs.appendList(classOrInterfaceOrRecordBodyDeclaration(className, isInterface, isRecord));
             if (token.pos <= endPosTable.errorEndPos) {
< prev index next >