8065753: javac crashing on a html-like file
Avoiding special-case in error recovery for bad token on position 0. Reviewed-by: jjg
This commit is contained in:
parent
78fd11386c
commit
113babff27
langtools
src/jdk.compiler/share/classes/com/sun/tools/javac/parser
test/tools/javac/parser
@ -3067,7 +3067,7 @@ public class JavacParser implements Parser {
|
||||
boolean checkForImports = true;
|
||||
boolean firstTypeDecl = true;
|
||||
while (token.kind != EOF) {
|
||||
if (token.pos > 0 && token.pos <= endPosTable.errorEndPos) {
|
||||
if (token.pos <= endPosTable.errorEndPos) {
|
||||
// error recovery
|
||||
skip(checkForImports, false, false, false);
|
||||
if (token.kind == EOF)
|
||||
@ -4083,7 +4083,7 @@ public class JavacParser implements Parser {
|
||||
/**
|
||||
* Store the last error position.
|
||||
*/
|
||||
protected int errorEndPos;
|
||||
protected int errorEndPos = Position.NOPOS;
|
||||
|
||||
public AbstractEndPosTable(JavacParser parser) {
|
||||
this.parser = parser;
|
||||
|
@ -23,7 +23,7 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 7073631 7159445 7156633 8028235
|
||||
* @bug 7073631 7159445 7156633 8028235 8065753
|
||||
* @summary tests error and diagnostics positions
|
||||
* @author Jan Lahoda
|
||||
*/
|
||||
@ -49,8 +49,10 @@ import com.sun.source.util.SourcePositions;
|
||||
import com.sun.source.util.TreeScanner;
|
||||
import com.sun.source.util.Trees;
|
||||
import com.sun.tools.javac.api.JavacTaskImpl;
|
||||
import com.sun.tools.javac.main.Main;
|
||||
import com.sun.tools.javac.tree.JCTree;
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
@ -941,6 +943,19 @@ public class JavacParserTest extends TestCase {
|
||||
TypeKind.VOID);
|
||||
}
|
||||
|
||||
@Test //JDK-8065753
|
||||
void testWrongFirstToken() throws IOException {
|
||||
String code = "<";
|
||||
String expectedErrors = "Test.java:1:1: compiler.err.expected3: class, interface, enum\n" +
|
||||
"1 error\n";
|
||||
StringWriter out = new StringWriter();
|
||||
JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(out, fm, null,
|
||||
Arrays.asList("-XDrawDiagnostics"), null, Arrays.asList(new MyFileObject(code)));
|
||||
|
||||
assertEquals("the error code is not correct", Main.Result.ERROR, ct.doCall());
|
||||
assertEquals("the error message is not correct", expectedErrors, out.toString());
|
||||
}
|
||||
|
||||
void run(String[] args) throws Exception {
|
||||
int passed = 0, failed = 0;
|
||||
final Pattern p = (args != null && args.length > 0)
|
||||
|
Loading…
x
Reference in New Issue
Block a user