Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
8228451: NPE in Attr.java when -XDshould-stop.ifError=FLOW
Avoiding parsing of compound assignment as a type.

Reviewed-by: jjg, vromero
  • Loading branch information
Jan Lahoda committed Mar 4, 2020
1 parent 9d57eef commit 0c9983887d7c53818cf79c3ac7450bb4a3929b9b
Showing with 31 additions and 3 deletions.
  1. +1 −1 src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java
  2. +30 −2 test/langtools/tools/javac/parser/JavacParserTest.java
@@ -817,7 +817,7 @@ protected JCExpression term(int newmode) {
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 @@ void testBrokenEnum5() throws IOException {
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)

0 comments on commit 0c99838

Please sign in to comment.