1 /* 2 * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 /* 24 * @test 25 * @summary type-annotation written as regular annotation in anon classes 26 * @bug 8013065 27 */ 28 import java.lang.annotation.*; 29 import static java.lang.annotation.RetentionPolicy.*; 30 import static java.lang.annotation.ElementType.*; 31 import com.sun.tools.classfile.*; 32 33 /* 34 * A type-annotations on a field in an inner class not in a lambda expression 35 * results in RuntimeTypeAnnotations_attibute and RuntimeAnnotations_attribute. 36 * On a field in an innner class in a lambda expression, it leaves off the 37 * RuntimeAnnotations_attribute. 38 */ 39 public class T8013065 extends ClassfileTestHelper{ 40 public static void main(String[] args) throws Exception { 41 new T8013065().run(); 42 } 43 44 public void run() throws Exception { 45 expected_tvisibles = 1; 46 expected_tinvisibles = 1; 47 ClassFile cf = getClassFile("T8013065$Test$1$InnerAnon.class"); 48 for (Method m : cf.methods) { 49 test(cf, m); 50 } 51 countAnnotations(); 52 53 if (errors > 0) 54 throw new Exception(errors + " errors found"); 55 System.out.println("PASSED"); 56 } 57 58 /*********************** Test class **************************/ 59 class Test<T> { 60 Object mtest( Test<T> t){ return null; } 61 public void test() { 62 mtest( new Test<T>() { 63 class InnerAnon<U> { 64 @A @B String ia_m1(){ return null; }; 65 } 66 //comment below and they're written correctly. 67 InnerAnon<String> IA = new InnerAnon< String>(); 68 }); 69 } 70 } 71 @Retention(CLASS) @Target(TYPE_USE) @interface A { } 72 @Retention(RUNTIME) @Target(TYPE_USE) @interface B { } 73 }