提交 1af5bd62 编写于 作者: E emc

8022322: Reject default and static methods in annotation

Summary: Causes javac to reject static and default method declarations inside an annotation
Reviewed-by: jjg
上级 55c6bcac
...@@ -97,7 +97,6 @@ public class Flags { ...@@ -97,7 +97,6 @@ public class Flags {
public static final int MANDATED = 1<<15; public static final int MANDATED = 1<<15;
public static final int StandardFlags = 0x0fff; public static final int StandardFlags = 0x0fff;
public static final int ModifierFlags = StandardFlags & ~INTERFACE;
// Because the following access flags are overloaded with other // Because the following access flags are overloaded with other
// bit positions, we translate them when reading and writing class // bit positions, we translate them when reading and writing class
...@@ -287,7 +286,9 @@ public class Flags { ...@@ -287,7 +286,9 @@ public class Flags {
SYNCHRONIZED | FINAL | STRICTFP; SYNCHRONIZED | FINAL | STRICTFP;
public static final long public static final long
ExtendedStandardFlags = (long)StandardFlags | DEFAULT, ExtendedStandardFlags = (long)StandardFlags | DEFAULT,
ModifierFlags = ((long)StandardFlags & ~INTERFACE) | DEFAULT,
InterfaceMethodMask = ABSTRACT | STATIC | PUBLIC | STRICTFP | DEFAULT, InterfaceMethodMask = ABSTRACT | STATIC | PUBLIC | STRICTFP | DEFAULT,
AnnotationTypeElementMask = FINAL | ABSTRACT | PUBLIC | STRICTFP,
LocalVarFlags = FINAL | PARAMETER; LocalVarFlags = FINAL | PARAMETER;
......
...@@ -1050,6 +1050,7 @@ public class Check { ...@@ -1050,6 +1050,7 @@ public class Check {
long checkFlags(DiagnosticPosition pos, long flags, Symbol sym, JCTree tree) { long checkFlags(DiagnosticPosition pos, long flags, Symbol sym, JCTree tree) {
long mask; long mask;
long implicit = 0; long implicit = 0;
switch (sym.kind) { switch (sym.kind) {
case VAR: case VAR:
if (sym.owner.kind != TYP) if (sym.owner.kind != TYP)
...@@ -1070,7 +1071,10 @@ public class Check { ...@@ -1070,7 +1071,10 @@ public class Check {
} else } else
mask = ConstructorFlags; mask = ConstructorFlags;
} else if ((sym.owner.flags_field & INTERFACE) != 0) { } 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; mask = InterfaceMethodMask;
implicit = PUBLIC; implicit = PUBLIC;
if ((flags & DEFAULT) != 0) { if ((flags & DEFAULT) != 0) {
...@@ -1079,8 +1083,7 @@ public class Check { ...@@ -1079,8 +1083,7 @@ public class Check {
} else { } else {
mask = implicit = InterfaceMethodFlags; mask = implicit = InterfaceMethodFlags;
} }
} } else {
else {
mask = MethodFlags; mask = MethodFlags;
} }
// Imply STRICTFP if owner has STRICTFP set. // Imply STRICTFP if owner has STRICTFP set.
......
/*
* @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;}
}
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
/*
* @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();
}
NoDefaultAbstract.java:8:17: compiler.err.mod.not.allowed.here: default
1 error
/*
* @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;}
}
NoStatic.java:9:16: compiler.err.mod.not.allowed.here: static
NoStatic.java:9:20: compiler.err.intf.meth.cant.have.body
2 errors
/*
* @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();
}
NoStaticAbstract.java:9:16: compiler.err.mod.not.allowed.here: static
1 error
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册