Thu, 12 Sep 2013 22:40:29 +0100
8023558: Javac creates invalid bootstrap methods for complex lambda/methodref case
Reviewed-by: jjg
Contributed-by: maurizio.cimadamore@oracle.com, vicente.romero@oracle.com
1.1 --- a/src/share/classes/com/sun/tools/javac/comp/TransTypes.java Thu Sep 12 14:52:28 2013 -0400 1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/TransTypes.java Thu Sep 12 22:40:29 2013 +0100 1.3 @@ -833,7 +833,7 @@ 1.4 } 1.5 1.6 public void visitReference(JCMemberReference tree) { 1.7 - tree.expr = translate(tree.expr, null); 1.8 + tree.expr = translate(tree.expr, erasure(tree.expr.type)); 1.9 tree.type = erasure(tree.type); 1.10 result = tree; 1.11 }
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/test/tools/javac/lambda/8023558/T8023558a.java Thu Sep 12 22:40:29 2013 +0100 2.3 @@ -0,0 +1,38 @@ 2.4 +/* 2.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 2.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 2.7 + * 2.8 + * This code is free software; you can redistribute it and/or modify it 2.9 + * under the terms of the GNU General Public License version 2 only, as 2.10 + * published by the Free Software Foundation. 2.11 + * 2.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 2.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 2.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 2.15 + * version 2 for more details (a copy is included in the LICENSE file that 2.16 + * accompanied this code). 2.17 + * 2.18 + * You should have received a copy of the GNU General Public License version 2.19 + * 2 along with this work; if not, write to the Free Software Foundation, 2.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2.21 + * 2.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2.23 + * or visit www.oracle.com if you need additional information or have any 2.24 + * questions. 2.25 + */ 2.26 + 2.27 +/* 2.28 + * @test 2.29 + * @bug 8023558 2.30 + * @summary Javac creates invalid bootstrap methods for complex lambda/methodref case 2.31 + */ 2.32 +public class T8023558a { 2.33 + interface SAM<T> { 2.34 + T get(); 2.35 + } 2.36 + 2.37 + public static void main(String[] args) { 2.38 + SAM<SAM> sam = new SAM<SAM>() { public SAM get() { return null; } }; 2.39 + SAM temp = sam.get()::get; 2.40 + } 2.41 +}
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/test/tools/javac/lambda/8023558/T8023558b.java Thu Sep 12 22:40:29 2013 +0100 3.3 @@ -0,0 +1,58 @@ 3.4 +/* 3.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 3.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3.7 + * 3.8 + * This code is free software; you can redistribute it and/or modify it 3.9 + * under the terms of the GNU General Public License version 2 only, as 3.10 + * published by the Free Software Foundation. 3.11 + * 3.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 3.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 3.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 3.15 + * version 2 for more details (a copy is included in the LICENSE file that 3.16 + * accompanied this code). 3.17 + * 3.18 + * You should have received a copy of the GNU General Public License version 3.19 + * 2 along with this work; if not, write to the Free Software Foundation, 3.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 3.21 + * 3.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 3.23 + * or visit www.oracle.com if you need additional information or have any 3.24 + * questions. 3.25 + */ 3.26 + 3.27 +/* 3.28 + * @test 3.29 + * @bug 8023558 3.30 + * @summary Javac creates invalid bootstrap methods for complex lambda/methodref case 3.31 + */ 3.32 +public class T8023558b { 3.33 + 3.34 + interface Supplier<X> { 3.35 + X get(); 3.36 + } 3.37 + 3.38 + static class A { 3.39 + public A(Supplier<B> supplier) { } 3.40 + } 3.41 + 3.42 + static class B { } 3.43 + 3.44 + static class C { 3.45 + public B getB() { 3.46 + return new B(); 3.47 + } 3.48 + } 3.49 + 3.50 + public static void main(String[] args) { 3.51 + new T8023558b().test(T8023558b::getC); 3.52 + } 3.53 + 3.54 + private static C getC() { 3.55 + return new C(); 3.56 + } 3.57 + 3.58 + public void test(Supplier<C> supplier) { 3.59 + new A(supplier.get()::getB); 3.60 + } 3.61 +}
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 4.2 +++ b/test/tools/javac/lambda/8023558/T8023558c.java Thu Sep 12 22:40:29 2013 +0100 4.3 @@ -0,0 +1,39 @@ 4.4 +/* 4.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 4.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4.7 + * 4.8 + * This code is free software; you can redistribute it and/or modify it 4.9 + * under the terms of the GNU General Public License version 2 only, as 4.10 + * published by the Free Software Foundation. 4.11 + * 4.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 4.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 4.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 4.15 + * version 2 for more details (a copy is included in the LICENSE file that 4.16 + * accompanied this code). 4.17 + * 4.18 + * You should have received a copy of the GNU General Public License version 4.19 + * 2 along with this work; if not, write to the Free Software Foundation, 4.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 4.21 + * 4.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 4.23 + * or visit www.oracle.com if you need additional information or have any 4.24 + * questions. 4.25 + */ 4.26 + 4.27 +/* 4.28 + * @test 4.29 + * @bug 8023558 4.30 + * @summary Javac creates invalid bootstrap methods for complex lambda/methodref case 4.31 + */ 4.32 + 4.33 +interface SAM<T> { 4.34 + T get(); 4.35 +} 4.36 + 4.37 +public class T8023558c { 4.38 + public static void main(String[] args) { 4.39 + SAM<SAM> sam = () -> Object::new; 4.40 + SAM temp = sam.get()::get; 4.41 + } 4.42 +}