8022322: Reject default and static methods in annotation

Causes javac to reject static and default method declarations inside an annotation

Reviewed-by: jjg
This commit is contained in:
Eric McCorkle 2013-09-09 16:26:55 -04:00
parent 1704a9454c
commit 5b76a0d216
10 changed files with 56 additions and 4 deletions

View File

@ -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;

View File

@ -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.

View File

@ -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;}
}

View File

@ -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

View File

@ -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();
}

View File

@ -0,0 +1,2 @@
NoDefaultAbstract.java:8:17: compiler.err.mod.not.allowed.here: default
1 error

View File

@ -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;}
}

View File

@ -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

View File

@ -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();
}

View File

@ -0,0 +1,2 @@
NoStaticAbstract.java:9:16: compiler.err.mod.not.allowed.here: static
1 error