1 /*
   2  * Copyright (c) 2009, 2015, 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 /*
  25  * @test
  26  * @summary Wrong classfile attribution in inner class of lambda expression.
  27  * @bug 8010015
  28  * @modules jdk.compiler/com.sun.tools.classfile
  29  */
  30 
  31 import java.lang.annotation.*;
  32 import static java.lang.annotation.RetentionPolicy.*;
  33 import static java.lang.annotation.ElementType.*;
  34 import com.sun.tools.classfile.*;
  35 
  36 /*
  37  * A type-annotations on a field in an inner class not in a lambda expression
  38  * results in RuntimeTypeAnnotations_attibute and RuntimeAnnotations_attribute.
  39  * On a field in an innner class in a lambda expression, it leaves off the
  40  * RuntimeAnnotations_attribute.
  41  */
  42 public class T8010015 extends ClassfileTestHelper{
  43     public static void main(String[] args) throws Exception {
  44         new T8010015().run();
  45     }
  46 
  47     public void run() throws Exception {
  48         expected_tvisibles = 1;
  49         expected_visibles = 1;
  50         ClassFile cf = getClassFile("T8010015$Test$1innerClass.class");
  51         for (Field f : cf.fields) {
  52             test(cf, f);
  53         }
  54         countAnnotations();
  55 
  56         if (errors > 0)
  57             throw new Exception(errors + " errors found");
  58         System.out.println("PASSED");
  59     }
  60 
  61     /*********************** Test class **************************/
  62     interface MapFun<T, R> { R m( T n); }
  63     static class Test {
  64         MapFun<Class<?>,String> cs;
  65         void test() {
  66             cs = c -> {
  67                      class innerClass {
  68                          @A Class<?> icc = null;
  69                          innerClass(Class<?> _c) { icc = _c; }
  70                          String getString() { return icc.toString(); }
  71                      }
  72                      return new innerClass(c).getString();
  73             };
  74             System.out.println("cs.m : " + cs.m(Integer.class));
  75         }
  76 
  77     public static void main(String... args) {new Test().test(); }
  78     }
  79     @Retention(RUNTIME) @Target({TYPE_USE,FIELD}) @interface A { }
  80 }