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


Hello,

I'd like to ask for a review of a patch for:
https://bugs.openjdk.java.net/browse/JDK-8035890
(for JDK9 and backport to JDK8u)

The patch is here:
http://cr.openjdk.java.net/~jlahoda/8035890/webrev.01/

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() { };
}
@Target(ElementType.TYPE_USE)
@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.

Thanks,
     Jan


More information about the compiler-dev mailing list