Use of an annotation without @Target meta-annotation on a module declaration

Werner Dietl wdietl at
Fri Aug 30 00:35:20 UTC 2019

Since Java 8, the JavaDoc for java.lang.annotation.Target contains:

"If an @Target meta-annotation is not present on an annotation type T,
then an annotation of type T may be written as a modifier for any
declaration except a type parameter declaration."

In Java 9, the additional constant MODULE was added to
java.lang.annotation.ElementType for module declarations.

Should an annotation without @Target meta-annotation be usable on a
module declaration or not?

Take a file

module moduletest {}

and a file pgk/

package pkg;
public @interface Anno {}

The above specification would seem to allow the use of @Anno on
moduletest and ecj (tested with version 3.16.0) compiles the test case
However, javac version 11.0.1 gives the following error: error: annotation type not applicable to this kind
of declaration
1 error

The javac error goes away when adding a @Target(ElementType.MODULE)

Is this a bug in javac or is this a problem with the JavaDoc?

cu, WMD.


More information about the compiler-dev mailing list