RFR: JDK-8035890 - jdk8 javac -source 7 compiles test case it should not

Jan Lahoda jan.lahoda at oracle.com
Tue Mar 18 19:59:38 UTC 2014


I'd like to ask for a review of a patch for:
(for JDK9 and backport to JDK8u)

The patch is here:

The bug is that, when -source 7 is used, javac does not in some cases 
properly report errors for Java 8 constructs related to type 
annotations. The fix covers two cases:
First, consider this code:
import java.lang.annotation.*;
public class AnnotCopiedToAnonymous {
      private Object o1 = new @Annot Object();
      private Object o2 = new @Annot Object() { };
@interface Annot { }

The problem here is that JavacParser.creator parses the annotations as 
declaration annotations, which does not perform the source level check 
for source >= 8. The proposed patch changes the parser to parse the 
annotations as type annotations, which ensures the source level check is 
performed correctly (and also changes the tree kinds for the annotations 
to TYPE_ANNOTATION). An alternate solution would be to keep the current 
way of parsing these annotations, and add an explicit source level 
check, if that would be more appropriate.

The second case is like this:
public class AnnotAfterTypeParams {
     public <T> @Decl int foo() { return 0; }
@interface Decl { }

With -source 8, declaration annotations are accepted after method's type 
parameters, so reusing the same error as for type annotations did not 
seem appropriate, so I've added a new error when this situation is 
detected with -source 7.

Any comments are very welcome.


More information about the compiler-dev mailing list