JDK-8029017 : ElementType.TYPE_USE should be a logical superset of ElementType.TYPE and ANNOTATION_TYPE
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 8
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • Submitted: 2013-11-22
  • Updated: 2014-08-07
  • Resolved: 2014-01-24
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8 JDK 9
8u20 b01Fixed 9Fixed
Related Reports
Relates :  
Description
The following program doesn't compile (JDK8 b116) because javac thinks 
the containing annotation type (FooContainer) is applicable to more 
targets than the repeatable annotation type (Foo):

---
import java.lang.annotation.ElementType;
import java.lang.annotation.Repeatable;
import java.lang.annotation.Target;

@Target({ElementType.TYPE_USE})
@Repeatable(FooContainer.class)
@interface Foo {}

@Target({ElementType.TYPE, ElementType.TYPE_USE})
@interface FooContainer {
   Foo[] value();
}
---

In fact, the program should compile. The kinds of program element where 
FooContainer is applicable - type uses and type declarations - are the 
same kinds where Foo is applicable, which means FooContainer is a 
legitimate containing type for Foo. (TYPE_USE is logically a superset of 
TYPE, so the TYPE target on FooContainer is redundant.)

Here is the relevant text for JLS8 9.6.3 "Repeatable Annotation Types"
which is aware of the TYPE_USE construct from JSR 308:

---
T is applicable to at least the same kinds of program element as TC 
(��9.6.4.1). Specifically, if the kinds of program element where T is 
applicable are denoted by the set m1, and the kinds of program element 
where TC is applicable are denoted by the set m2, then each kind in m2 
must occur in m1, except that:

- If the kind in m2 is java.lang.annotation.ElementType.ANNOTATION_TYPE, 
then at least
one of java.lang.annotation.ElementType.ANNOTATION_TYPE or
java.lang.annotation.ElementType.TYPE or
java.lang.annotation.ElementType.TYPE_USE must occur in m1.

- If the kind in m2 is java.lang.annotation.ElementType.TYPE,
then at least one of java.lang.annotation.ElementType.TYPE or
java.lang.annotation.ElementType.TYPE_USE must occur in m1.

- If the kind in m2 is java.lang.annotation.ElementType.TYPE_PARAMETER,
then at least one of java.lang.annotation.ElementType.TYPE_PARAMETER or
java.lang.annotation.ElementType.TYPE_USE must occur in m1.
---
Comments
Release team: Approved for deferral.
06-12-2013

I take issue with the previous comment: "Maybe TYPE_USE should be some kind of superset but also maybe container should not have Target of its own and simply use the Target(s) of that which it contains." The semantics of a containing annotation type were carefully designed in consultation with Java EE. It is perfectly legitimate for a containing annotation type to have its own @Target meta-annotation. This is not an RFE. We had already considered how TYPE and ANNOTATION_TYPE work in the targets of repeatable v. containing annotation types; the logic extends smoothly to TYPE_USE and TYPE (and ANNOTATION_TYPE), but is not being implemented.
25-11-2013

8-defer-SQE-OK: TYPE_USE and TYPE are both ElementType enum values. This is part RFE. Maybe TYPE_USE should be some kind of superset but also maybe container should not have Target of its own and simply use the Target(s) of that which it contains.
25-11-2013

Release team: Need QA to say OK to this before deferring it.
25-11-2013