some new bugs

Steve Sides steve.sides at oracle.com
Fri Feb 22 18:07:22 PST 2013


Hi Werner,
I have been looking at type-annotations in anonymous and inner classes.
I have a few new bugs. They are showing yet in bugs.sun.com, but they 
should by tomorrow(?).
Only the first one is a jtreg test. The other 2 are part of a larger 
test with some classfile checking, but I
put the sample code here so you can javac,javap it.

-steve

8008751 - Type Annotation on array level in nested class of anonymous 
class results in NPE at
com.sun.tools.javac.code.TypeAnnotations$TypeAnnotationPositions.resolveFrame(TypeAnnotations.java:792) 

8<- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
- - - - - - - - - -
/*
  * @test
  * @summary type-annotation on array level in nested class results in NPE
  * @bug 8008751
  */
import java.lang.annotation.*;
import static java.lang.annotation.RetentionPolicy.*;
import static java.lang.annotation.ElementType.*;
import java.util.List;

class T8008751 {
     Object mtest( T8008751 t){ return null;  }
     Object mmtest( T8008751 t){ return null;  }
     public void test() {
        mtest( new T8008751() {
                 class InnerAnon {
                     @A("ok") String s = (@A("ok") String)( new @A("ok") 
Object());
                     @A("ok") Object @A("NPE")[] [] ia_sa1 = null;
                 }
                 // If not instanciated, no crash.
                 InnerAnon IA = new InnerAnon();
            });
    }
}
@Retention(RUNTIME) @Target(TYPE_USE)  @interface A { String value(); }


8008762 - Type annotation on inner class in anonymous class show up as 
regular type annotations
8<- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
- - - - - - - - - -
import java.lang.annotation.*;
import static java.lang.annotation.RetentionPolicy.*;
import static java.lang.annotation.ElementType.*;

class Test1 { // Test1.class
     @A @B String data = "test";
     @A @B String m(){ return null; };
     Object mtest( Test1 t){ return null; }
     public void test() {
         mtest( new Test1() { // Test1$1.class
                 @A @B String a_data = "test";
                 @A @B String a_m(){ return null; };
                 class InnerAnon { // Test1$1$InnerAnon.class
                      @A @B String ai_data = "test";
                      @A @B String ai_m(){ return null; };
                 }
                  InnerAnon IA = new InnerAnon();
            });
    }
}

@Retention(RUNTIME) @Target(TYPE_USE) @interface A { }
@Retention(CLASS) @Target(TYPE_USE) @interface B { }


8008769 - Repeated type-annotations on type parameter of local variable 
are not written to classfile.
8<- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
- - - - - - - - - -
import java.lang.annotation.*;
import static java.lang.annotation.RetentionPolicy.*;
import static java.lang.annotation.ElementType.*;

class Test<T> {
     Test<@A @A @A String> t = new Test<>(); //ok

     public void test() {
         Test<@B String> t1 = new Test<>(); //ok
         Test<@A @A @A String> t2 = new Test<>(); //not ok
    }
}

@Target(TYPE_USE) @Repeatable( AC.class ) @interface A { }
@Target(TYPE_USE) @interface AC { A[] value(); }
@Target(TYPE_USE) @Repeatable( BC.class ) @interface B { }
@Target(TYPE_USE) @interface BC { B[] value(); }




More information about the type-annotations-dev mailing list