JDK-8061597 : Type annotations on class literals are accepted by compiler when used with primitive types
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 9
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • Submitted: 2014-10-21
  • Updated: 2015-01-27
  • Resolved: 2015-01-27
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 9
9Resolved
Related Reports
Duplicate :  
Relates :  
Description
According to the spec, type annotations on class literals are prohibited (http://baloo.ru.oracle.com/jenkins/job/jck8a-lang/lastSuccessfulBuild/artifact/build/out/htmlout/jls-15.html#jls-15.8.2-110)

The following code, however, is accepted by the compiler:

class Test {
   

    public static void test() {
        Class c = int @Simple   [] .class;     //compiles
    }

}
@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER }) @interface Simple {}


The same code is not compiled if we use Integer instead of int:
class Test {
   

    public static void test() {
        Class c = int @Simple   [] .class;     // javac error here
    }

}
@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER }) @interface Simple {}

The situation is similar for other primitive types.

Seems like a regression, because in b27 both cases were rejected by the compiler, and in b34 the situation is as described.



Comments
Confirming that the tests pass under b47.
27-01-2015

This is the same as https://bugs.openjdk.java.net/browse/JDK-8027888. I have a patch there under review.
30-12-2014

ILW: M (conformance, no practical), M (type annotations), H (none) -> P3
02-12-2014