diff --git a/src/share/classes/com/sun/tools/javac/code/Flags.java b/src/share/classes/com/sun/tools/javac/code/Flags.java index b2da28073639b1e289967549000ae2f3a5cdc34a..3a4084ed2a88769f5a84671236a30c4c4426e101 100644 --- a/src/share/classes/com/sun/tools/javac/code/Flags.java +++ b/src/share/classes/com/sun/tools/javac/code/Flags.java @@ -97,7 +97,6 @@ public class Flags { public static final int MANDATED = 1<<15; public static final int StandardFlags = 0x0fff; - public static final int ModifierFlags = StandardFlags & ~INTERFACE; // Because the following access flags are overloaded with other // bit positions, we translate them when reading and writing class @@ -287,7 +286,9 @@ public class Flags { SYNCHRONIZED | FINAL | STRICTFP; public static final long ExtendedStandardFlags = (long)StandardFlags | DEFAULT, + ModifierFlags = ((long)StandardFlags & ~INTERFACE) | DEFAULT, InterfaceMethodMask = ABSTRACT | STATIC | PUBLIC | STRICTFP | DEFAULT, + AnnotationTypeElementMask = FINAL | ABSTRACT | PUBLIC | STRICTFP, LocalVarFlags = FINAL | PARAMETER; diff --git a/src/share/classes/com/sun/tools/javac/comp/Check.java b/src/share/classes/com/sun/tools/javac/comp/Check.java index 5529627ed90a2ec1ea9904e7777791a7d2a74d8b..59d6c7b4468e6082a66f3aad7272f3ae8c925e07 100644 --- a/src/share/classes/com/sun/tools/javac/comp/Check.java +++ b/src/share/classes/com/sun/tools/javac/comp/Check.java @@ -1050,6 +1050,7 @@ public class Check { long checkFlags(DiagnosticPosition pos, long flags, Symbol sym, JCTree tree) { long mask; long implicit = 0; + switch (sym.kind) { case VAR: if (sym.owner.kind != TYP) @@ -1070,7 +1071,10 @@ public class Check { } else mask = ConstructorFlags; } else if ((sym.owner.flags_field & INTERFACE) != 0) { - if ((flags & (DEFAULT | STATIC)) != 0) { + if ((sym.owner.flags_field & ANNOTATION) != 0) { + mask = AnnotationTypeElementMask; + implicit = PUBLIC | ABSTRACT; + } else if ((flags & (DEFAULT | STATIC)) != 0) { mask = InterfaceMethodMask; implicit = PUBLIC; if ((flags & DEFAULT) != 0) { @@ -1079,8 +1083,7 @@ public class Check { } else { mask = implicit = InterfaceMethodFlags; } - } - else { + } else { mask = MethodFlags; } // Imply STRICTFP if owner has STRICTFP set. diff --git a/test/tools/javac/annotations/neg/NoDefault.java b/test/tools/javac/annotations/neg/NoDefault.java new file mode 100644 index 0000000000000000000000000000000000000000..282bc98bf3a6d23d6ad790ceae795dbee1074631 --- /dev/null +++ b/test/tools/javac/annotations/neg/NoDefault.java @@ -0,0 +1,9 @@ +/* + * @test /nodynamiccopyright/ + * @bug 8022322 + * @summary Default methods are not allowed in an annotation. + * @compile/fail/ref=NoDefault.out -XDrawDiagnostics NoDefault.java + */ +@interface NoDefault { + default int m() {return 0;} +} diff --git a/test/tools/javac/annotations/neg/NoDefault.out b/test/tools/javac/annotations/neg/NoDefault.out new file mode 100644 index 0000000000000000000000000000000000000000..ffcbf8233516b94e8a96bc1c96a635c3d876051e --- /dev/null +++ b/test/tools/javac/annotations/neg/NoDefault.out @@ -0,0 +1,3 @@ +NoDefault.java:8:17: compiler.err.mod.not.allowed.here: default +NoDefault.java:8:21: compiler.err.intf.meth.cant.have.body +2 errors \ No newline at end of file diff --git a/test/tools/javac/annotations/neg/NoDefaultAbstract.java b/test/tools/javac/annotations/neg/NoDefaultAbstract.java new file mode 100644 index 0000000000000000000000000000000000000000..6c288810fe125bd69dfd7781abbcfdd5347624e1 --- /dev/null +++ b/test/tools/javac/annotations/neg/NoDefaultAbstract.java @@ -0,0 +1,9 @@ +/* + * @test /nodynamiccopyright/ + * @bug 8022322 + * @summary Default methods are not allowed in an annotation. + * @compile/fail/ref=NoDefaultAbstract.out -XDrawDiagnostics NoDefaultAbstract.java + */ +@interface NoDefaultAbstract { + default int m(); +} diff --git a/test/tools/javac/annotations/neg/NoDefaultAbstract.out b/test/tools/javac/annotations/neg/NoDefaultAbstract.out new file mode 100644 index 0000000000000000000000000000000000000000..ea445c68e130045f1b5fb652e10da0489584891f --- /dev/null +++ b/test/tools/javac/annotations/neg/NoDefaultAbstract.out @@ -0,0 +1,2 @@ +NoDefaultAbstract.java:8:17: compiler.err.mod.not.allowed.here: default +1 error diff --git a/test/tools/javac/annotations/neg/NoStatic.java b/test/tools/javac/annotations/neg/NoStatic.java new file mode 100644 index 0000000000000000000000000000000000000000..3a62dc7c748ec2f3d005e66fd916dbc0ff45a6ce --- /dev/null +++ b/test/tools/javac/annotations/neg/NoStatic.java @@ -0,0 +1,10 @@ +/* + * @test /nodynamiccopyright/ + * @bug 8022322 + * @summary Static methods are not allowed in an annotation. + * @compile/fail/ref=NoStatic.out -XDrawDiagnostics NoStatic.java + */ + +@interface NoStatic { + static int m() {return 0;} +} diff --git a/test/tools/javac/annotations/neg/NoStatic.out b/test/tools/javac/annotations/neg/NoStatic.out new file mode 100644 index 0000000000000000000000000000000000000000..8d9d313191586f06419ce4202c200f54805b09b3 --- /dev/null +++ b/test/tools/javac/annotations/neg/NoStatic.out @@ -0,0 +1,3 @@ +NoStatic.java:9:16: compiler.err.mod.not.allowed.here: static +NoStatic.java:9:20: compiler.err.intf.meth.cant.have.body +2 errors diff --git a/test/tools/javac/annotations/neg/NoStaticAbstract.java b/test/tools/javac/annotations/neg/NoStaticAbstract.java new file mode 100644 index 0000000000000000000000000000000000000000..af27fa75b9aceb7c88982f0c5ab6304f6d20c352 --- /dev/null +++ b/test/tools/javac/annotations/neg/NoStaticAbstract.java @@ -0,0 +1,10 @@ +/* + * @test /nodynamiccopyright/ + * @bug 8022322 + * @summary Static methods are not allowed in an annotation. + * @compile/fail/ref=NoStaticAbstract.out -XDrawDiagnostics NoStaticAbstract.java + */ + +@interface NoStaticAbstract { + static int m(); +} diff --git a/test/tools/javac/annotations/neg/NoStaticAbstract.out b/test/tools/javac/annotations/neg/NoStaticAbstract.out new file mode 100644 index 0000000000000000000000000000000000000000..694cea1771fffb8f3037b8b70c41818cfeb7d9e0 --- /dev/null +++ b/test/tools/javac/annotations/neg/NoStaticAbstract.out @@ -0,0 +1,2 @@ +NoStaticAbstract.java:9:16: compiler.err.mod.not.allowed.here: static +1 error