From 18f70cfdd2f115b1bb558d498ee540f61207dd2a Mon Sep 17 00:00:00 2001 From: Vicente Romero Date: Mon, 27 Nov 2017 10:40:42 -0500 Subject: [PATCH] 8185983: Javac should reject TypeArguments on field access expression Reviewed-by: mcimadamore --- .../com/sun/tools/javac/parser/JavacParser.java | 3 +++ .../javac/T8185983/RejectTypeArgsOnSelectTest.java | 12 ++++++++++++ .../javac/T8185983/RejectTypeArgsOnSelectTest.out | 2 ++ 3 files changed, 17 insertions(+) create mode 100644 test/langtools/tools/javac/T8185983/RejectTypeArgsOnSelectTest.java create mode 100644 test/langtools/tools/javac/T8185983/RejectTypeArgsOnSelectTest.out diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java index 354f3433c7f..12a4a693a17 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java @@ -1319,6 +1319,9 @@ public class JavacParser implements Parser { break loop; case DOT: nextToken(); + if (token.kind == TokenKind.IDENTIFIER && typeArgs != null) { + return illegal(); + } int oldmode = mode; mode &= ~NOPARAMS; typeArgs = typeArgumentsOpt(EXPR); diff --git a/test/langtools/tools/javac/T8185983/RejectTypeArgsOnSelectTest.java b/test/langtools/tools/javac/T8185983/RejectTypeArgsOnSelectTest.java new file mode 100644 index 00000000000..08e7fd99551 --- /dev/null +++ b/test/langtools/tools/javac/T8185983/RejectTypeArgsOnSelectTest.java @@ -0,0 +1,12 @@ +/* + * @test /nodynamiccopyright/ + * @bug 8185983 + * @summary Javac should reject TypeArguments on field access expression + * @compile/fail/ref=RejectTypeArgsOnSelectTest.out -XDrawDiagnostics RejectTypeArgsOnSelectTest.java + */ + +import java.util.*; + +class RejectTypeArgsOnSelectTest { + Iterator nullIter = Collections.EMPTY_LIST.iterator(); +} diff --git a/test/langtools/tools/javac/T8185983/RejectTypeArgsOnSelectTest.out b/test/langtools/tools/javac/T8185983/RejectTypeArgsOnSelectTest.out new file mode 100644 index 00000000000..94400dda8aa --- /dev/null +++ b/test/langtools/tools/javac/T8185983/RejectTypeArgsOnSelectTest.out @@ -0,0 +1,2 @@ +RejectTypeArgsOnSelectTest.java:11:104: compiler.err.illegal.start.of.expr +1 error