8254023: A module declaration is not allowed to be a target of an annotation that lacks an @Target meta-annotation
Guoxiong Li
lgxbslgx at gmail.com
Mon Oct 12 10:31:35 UTC 2020
Hi,
I have viewed the Java Language Specifications(JLS) from 8 to 15 about the
description of this issue. The most important content is the last paragraph
in JLS 9.6.4.1.
The Java versions, from 8 to 13 included, state it as below:
>> If an annotation of type java.lang.annotation.Target is not present on
the
declaration of an annotation type T , then T is applicable in all
declaration contexts
except type parameter declarations, and in no type contexts.
These contexts are the syntactic locations where annotations were allowed
in Java SE 7.
The Java versions 14 and 15 state it as below:
>>If an annotation of type java.lang.annotation.Target is not present on the
declaration of an annotation type T , then T is applicable in all nine
declaration
contexts and in all 16 type contexts.
So I think it is an issue of incompatibility between the implementation of
javac and the standard of JLS in version 14 and 15.
I write a draft patch to solve this issue. Could anyone give more
information about this problem or some suggestions to my idea and patch?
The patch is shown below.
diff --git
a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java
b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java
index f1725857891..758c462b829 100644
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java
@@ -119,7 +119,8 @@ public class Check {
names = Names.instance(context);
dfltTargetMeta = new Name[] { names.PACKAGE, names.TYPE,
names.FIELD, names.RECORD_COMPONENT, names.METHOD,
names.CONSTRUCTOR,
- names.ANNOTATION_TYPE, names.LOCAL_VARIABLE, names.PARAMETER};
+ names.ANNOTATION_TYPE, names.LOCAL_VARIABLE, names.PARAMETER,
+ names.MODULE, names.TYPE_PARAMETER, names.TYPE_USE };
log = Log.instance(context);
rs = Resolve.instance(context);
syms = Symtab.instance(context);
diff --git a/test/langtools/tools/javac/annotations/8254023/T8254023.java
b/test/langtools/tools/javac/annotations/8254023/T8254023.java
new file mode 100644
index 00000000000..ec64f42a7a9
--- /dev/null
+++ b/test/langtools/tools/javac/annotations/8254023/T8254023.java
@@ -0,0 +1,7 @@
+
+/**
+ * @test
+ * @bug 8254023
+ * @summary A module declaration is not allowed to be a target of an
annotation that lacks an (at)Target meta-annotation
+ * @compile module-info.java test/A.java
+ */
diff --git
a/test/langtools/tools/javac/annotations/8254023/module-info.java
b/test/langtools/tools/javac/annotations/8254023/module-info.java
new file mode 100644
index 00000000000..936038a24a9
--- /dev/null
+++ b/test/langtools/tools/javac/annotations/8254023/module-info.java
@@ -0,0 +1,2 @@
+ at test.A
+module test { }
\ No newline at end of file
diff --git a/test/langtools/tools/javac/annotations/8254023/test/A.java
b/test/langtools/tools/javac/annotations/8254023/test/A.java
new file mode 100644
index 00000000000..824f0362207
--- /dev/null
+++ b/test/langtools/tools/javac/annotations/8254023/test/A.java
@@ -0,0 +1,3 @@
+package test;
+
+public @interface A { }
Best Regards.
------------------------
Name: Guoxiong Li
Email: lgxbslgx at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/compiler-dev/attachments/20201012/c95390aa/attachment.htm>
More information about the compiler-dev
mailing list