8157519: Error messages when compiling a malformed module-info.java confusing
authorsadayapalam
Tue, 16 Aug 2016 09:13:33 +0530
changeset 40501 8455b59aa04a
parent 40500 f293dbb81a53
child 40502 59dadf1bedbe
8157519: Error messages when compiling a malformed module-info.java confusing Reviewed-by: jjg
langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java
langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties
langtools/test/tools/javac/diags/examples/InvalidModuleDirective/module-info.java
langtools/test/tools/javac/modules/InvalidModuleDirective/module-info.java
langtools/test/tools/javac/modules/InvalidModuleDirective/moduleinfo.out
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java	Mon Aug 15 18:00:36 2016 -0700
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java	Tue Aug 16 09:13:33 2016 +0530
@@ -3238,6 +3238,8 @@
                 accept(SEMI);
                 defs.append(toP(F.at(pos).Uses(service)));
             } else {
+                setErrorEndPos(pos);
+                reportSyntaxError(pos, "invalid.module.directive");
                 break;
             }
         }
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties	Mon Aug 15 18:00:36 2016 -0700
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties	Tue Aug 16 09:13:33 2016 +0530
@@ -672,6 +672,9 @@
 compiler.err.cannot.create.array.with.diamond=\
     cannot create array with ''<>''
 
+compiler.err.invalid.module.directive=\
+  module directive keyword or ''}'' expected
+
 #
 # limits.  We don't give the limits in the diagnostic because we expect
 # them to change, yet we want to use the same diagnostic.  These are all
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/diags/examples/InvalidModuleDirective/module-info.java	Tue Aug 16 09:13:33 2016 +0530
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2016, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+// key: compiler.err.invalid.module.directive
+
+module java.transaction {
+  requires java.base;
+  resuires javax.interceptor.javax.interceptor.api;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/modules/InvalidModuleDirective/module-info.java	Tue Aug 16 09:13:33 2016 +0530
@@ -0,0 +1,15 @@
+/*
+ * @test /nodynamiccopyright/
+ * @bug 8157519
+ * @summary Error messages when compiling a malformed module-info.java confusing
+ * @compile/fail/ref=moduleinfo.out -XDrawDiagnostics module-info.java
+ */
+
+module java.transaction {
+  requires java.base;
+  resuires javax.interceptor.javax.interceptor.api;
+  requires public javax.enterprise.cdi.api;
+  requires public java.sql;
+  requires public java.rmi;
+  export javax.transaction;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/modules/InvalidModuleDirective/moduleinfo.out	Tue Aug 16 09:13:33 2016 +0530
@@ -0,0 +1,2 @@
+module-info.java:10:3: compiler.err.invalid.module.directive
+1 error