javac bugs re: class literals and receiver parameters

Alex Buckley alex.buckley at oracle.com
Tue Oct 22 16:13:23 PDT 2013


Hi list, two bugs to report:

1. Annotations are incorrectly allowed within array types in class literals:

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

@Target(ElementType.TYPE_USE)
@interface T {}

public class X {
   public static void main(String[] args) {
     Class<?> b = @T int . class;  // Correctly forbidden
     Class<?> c = int @T [] . class;  // Incorrectly allowed
     Class<?> d = int [] @T [] . class;  // Incorrectly allowed
   }
}

(Formally, a class literal involves a _type name_, not a _type_. For 
example, you cannot say List<String>.class or even List<?>.class. As a 
result, there is no type within a class literal to annotate. The 308.pdf 
file discusses how JLS8 should use TypeName rather than Type in the 
grammar of class literals in 15.8, thus clarifying that this is not a 
type use.)

2. The 'final' modifier is incorrectly allowed on a receiver parameter; 
syntactically only modifiers should be allowed in that location.

('final' was not permitted in the longstanding 
java-annotation-design.pdf file, and I am updating the 308.pdf file to 
conform to that.)

Alex


More information about the type-annotations-dev mailing list