changeset 45867:ca77ebd05a06

8074364: Update error message for incorrect annotation type declaration Summary: Issue a more direct, specific error when an annotation type is declared where it is disallowed Reviewed-by: sadayapalam
author pmuthuswamy
date Wed, 12 Jul 2017 12:27:57 +0530
parents 5070422dda41
children 6a58a7837e93
files langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties langtools/test/tools/javac/IllegalAnnotation.java langtools/test/tools/javac/IllegalAnnotation.out langtools/test/tools/javac/diags/examples/IllegalAnnotationDeclaration.java
diffstat 5 files changed, 36 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java	Tue Jul 11 18:09:10 2017 -0700
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java	Wed Jul 12 12:27:57 2017 +0530
@@ -1207,7 +1207,7 @@
         long illegal = flags & ExtendedStandardFlags & ~mask;
         if (illegal != 0) {
             if ((illegal & INTERFACE) != 0) {
-                log.error(pos, Errors.IntfNotAllowedHere);
+                log.error(pos, ((flags & ANNOTATION) != 0) ? Errors.AnnotationDeclNotAllowedHere : Errors.IntfNotAllowedHere);
                 mask |= INTERFACE;
             }
             else {
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties	Tue Jul 11 18:09:10 2017 -0700
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties	Wed Jul 12 12:27:57 2017 +0530
@@ -311,6 +311,9 @@
 compiler.err.cant.extend.intf.annotation=\
     ''extends'' not allowed for @interfaces
 
+compiler.err.annotation.decl.not.allowed.here=\
+    annotation type declaration not allowed here
+
 # 0: symbol
 compiler.err.cant.inherit.from.final=\
     cannot inherit from final {0}
--- a/langtools/test/tools/javac/IllegalAnnotation.java	Tue Jul 11 18:09:10 2017 -0700
+++ b/langtools/test/tools/javac/IllegalAnnotation.java	Wed Jul 12 12:27:57 2017 +0530
@@ -1,6 +1,6 @@
 /**
  * @test  /nodynamiccopyright/
- * @bug 5012028 6384539
+ * @bug 5012028 6384539 8074364
  * @summary javac crash when declare an annotation type illegally
  *
  * @compile/fail/ref=IllegalAnnotation.out -XDrawDiagnostics IllegalAnnotation.java
--- a/langtools/test/tools/javac/IllegalAnnotation.out	Tue Jul 11 18:09:10 2017 -0700
+++ b/langtools/test/tools/javac/IllegalAnnotation.out	Wed Jul 12 12:27:57 2017 +0530
@@ -1,2 +1,2 @@
-IllegalAnnotation.java:10:10: compiler.err.intf.not.allowed.here
+IllegalAnnotation.java:10:10: compiler.err.annotation.decl.not.allowed.here
 1 error
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/diags/examples/IllegalAnnotationDeclaration.java	Wed Jul 12 12:27:57 2017 +0530
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2017, 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.annotation.decl.not.allowed.here
+
+class IllegalAnnotationDeclaration {
+    {
+        @interface SomeAnnotation { }
+    }
+}