mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 15:24:43 +02:00
8228451: NPE in Attr.java when -XDshould-stop.ifError=FLOW
Avoiding parsing of compound assignment as a type. Reviewed-by: jjg, vromero
This commit is contained in:
parent
9d57eefe6e
commit
0c9983887d
2 changed files with 31 additions and 3 deletions
|
@ -817,7 +817,7 @@ public class JavacParser implements Parser {
|
|||
JCExpression term() {
|
||||
JCExpression t = term1();
|
||||
if ((mode & EXPR) != 0 &&
|
||||
token.kind == EQ || PLUSEQ.compareTo(token.kind) <= 0 && token.kind.compareTo(GTGTGTEQ) <= 0)
|
||||
(token.kind == EQ || PLUSEQ.compareTo(token.kind) <= 0 && token.kind.compareTo(GTGTGTEQ) <= 0))
|
||||
return termRest(t);
|
||||
else
|
||||
return t;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2011, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -23,7 +23,7 @@
|
|||
|
||||
/*
|
||||
* @test
|
||||
* @bug 7073631 7159445 7156633 8028235 8065753 8205418 8205913
|
||||
* @bug 7073631 7159445 7156633 8028235 8065753 8205418 8205913 8228451
|
||||
* @summary tests error and diagnostics positions
|
||||
* @author Jan Lahoda
|
||||
* @modules jdk.compiler/com.sun.tools.javac.api
|
||||
|
@ -1464,6 +1464,34 @@ public class JavacParserTest extends TestCase {
|
|||
expectedAST);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCompoundAssignment() throws IOException {
|
||||
assert tool != null;
|
||||
|
||||
String code = "package test; class Test { v += v v;}";
|
||||
StringWriter output = new StringWriter();
|
||||
JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(output, fm, null, List.of("-XDrawDiagnostics"),
|
||||
null, Arrays.asList(new MyFileObject(code)));
|
||||
CompilationUnitTree cut = ct.parse().iterator().next();
|
||||
List<String> actual = List.of(output.toString().split("\r?\n"));
|
||||
List<String> expected = List.of("Test.java:1:29: compiler.err.expected: token.identifier");
|
||||
|
||||
assertEquals("The expected and actual errors do not match, actual errors: " + actual,
|
||||
actual,
|
||||
expected);
|
||||
|
||||
String actualAST = cut.toString().replaceAll("\\R", "\n");
|
||||
String expectedAST = "package test;\n" +
|
||||
"\n" +
|
||||
"class Test {\n" +
|
||||
" v <error>;\n" +
|
||||
" v v;\n" +
|
||||
"}";
|
||||
assertEquals("The expected and actual AST do not match, actual AST: " + actualAST,
|
||||
actualAST,
|
||||
expectedAST);
|
||||
}
|
||||
|
||||
void run(String[] args) throws Exception {
|
||||
int passed = 0, failed = 0;
|
||||
final Pattern p = (args != null && args.length > 0)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue