LambdaInnerTypeVarReflect.java revision 3294:9adfb22ff08f
1/* 2 * Copyright (c) 2013, 2016, 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 * @bug 8005653 27 * @summary A lambda containing an inner class referencing an external type var 28 * @author Robert Field 29 * @modules jdk.compiler 30 * jdk.jdeps/com.sun.tools.javap 31 * @run main LambdaInnerTypeVarReflect 32 */ 33 34import java.io.StringWriter; 35import java.io.PrintWriter; 36import java.io.IOException; 37 38public class LambdaInnerTypeVarReflect { 39 40 static int assertionCount = 0; 41 42 static void assertTrue(boolean cond) { 43 assertionCount++; 44 if (!cond) 45 throw new AssertionError(); 46 } 47 48 interface I { 49 C doit(); 50 } 51 52 abstract class C { 53 abstract Object it(); 54 } 55 56 class TV { 57 C go() { 58 return foo("Frump").doit(); 59 } 60 61 <RRRRR> I foo(RRRRR r) { 62 return () -> new C() { 63 public RRRRR xxxxx = r; 64 @Override 65 Object it() { return xxxxx; }; 66 }; 67 } 68 } 69 70 void test1() throws IOException { 71 char[] buffer = new char[1024]; 72 String innerName = new TV().go().getClass().getName(); 73 StringWriter sw = new StringWriter(); 74 PrintWriter pw = new PrintWriter(sw); 75 int exitCode = com.sun.tools.javap.Main.run(new String[] {innerName}, pw); 76 assertTrue(exitCode == 0); 77 78 String javapOut = sw.toString(); 79 assertTrue(javapOut.contains(innerName)); 80 assertTrue(!javapOut.contains("RRRRR")); 81 } 82 83 public static void main(String[] args) throws IOException { 84 LambdaInnerTypeVarReflect t = new LambdaInnerTypeVarReflect(); 85 t.test1(); 86 assertTrue(assertionCount == 3); 87 } 88} 89