-
Bug
-
Resolution: Unresolved
-
P3
-
None
javac correctly rejects the following type annotation on `One.Inner`, since annotations on `One` are not admissible (JLS 9.7.4).
```
import static java.lang.annotation.ElementType.TYPE_USE;
import java.lang.annotation.Target;
abstract class One {
@Target(TYPE_USE)
@interface A {}
static class Inner {}
@A One.Inner f;
}
```
One.java:11: error: scoping construct cannot be annotated with type-use annotation: @One.A
@A One.Inner f;
^
1 error
However in this example the annotation has been modified to target both 'FIELD' and 'TYPE_USE' locations, and javac both emits the annotation as a declaration on the field, and as a type annotation on `One` (which is incorrect):
```
import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.TYPE_USE;
import java.lang.annotation.Target;
abstract class Two {
@Target({FIELD, TYPE_USE})
@interface A {}
static class Inner {}
@A Two.Inner f;
}
```
Two$Inner f;
descriptor: LTwo$Inner;
flags: (0x0000)
RuntimeInvisibleAnnotations:
0: #12()
Two$A
RuntimeInvisibleTypeAnnotations:
0: #12(): FIELD
Two$A
I think the compiler should reject both inputs.
```
import static java.lang.annotation.ElementType.TYPE_USE;
import java.lang.annotation.Target;
abstract class One {
@Target(TYPE_USE)
@interface A {}
static class Inner {}
@A One.Inner f;
}
```
One.java:11: error: scoping construct cannot be annotated with type-use annotation: @One.A
@A One.Inner f;
^
1 error
However in this example the annotation has been modified to target both 'FIELD' and 'TYPE_USE' locations, and javac both emits the annotation as a declaration on the field, and as a type annotation on `One` (which is incorrect):
```
import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.TYPE_USE;
import java.lang.annotation.Target;
abstract class Two {
@Target({FIELD, TYPE_USE})
@interface A {}
static class Inner {}
@A Two.Inner f;
}
```
Two$Inner f;
descriptor: LTwo$Inner;
flags: (0x0000)
RuntimeInvisibleAnnotations:
0: #12()
Two$A
RuntimeInvisibleTypeAnnotations:
0: #12(): FIELD
Two$A
I think the compiler should reject both inputs.
- relates to
-
JDK-8077585 No compiler error on duplicate annotation leads to a run-time exception
- Open
-
JDK-8198526 getAnnotatedOwnerType does not handle static nested classes correctly
- Resolved