Thu, 25 Jul 2013 14:47:43 +0100
8020804: javac crashes when speculative attribution infers intersection type with array component
Summary: Assertion is causing javac to crash because of lack of support for arrays in intersection types
Reviewed-by: jjg
1.1 --- a/src/share/classes/com/sun/tools/javac/code/Types.java Thu Jul 25 11:02:27 2013 +0200 1.2 +++ b/src/share/classes/com/sun/tools/javac/code/Types.java Thu Jul 25 14:47:43 2013 +0100 1.3 @@ -620,7 +620,9 @@ 1.4 * (ii) perform functional interface bridge calculation. 1.5 */ 1.6 public ClassSymbol makeFunctionalInterfaceClass(Env<AttrContext> env, Name name, List<Type> targets, long cflags) { 1.7 - Assert.check(targets.nonEmpty() && isFunctionalInterface(targets.head)); 1.8 + if (targets.isEmpty() || !isFunctionalInterface(targets.head)) { 1.9 + return null; 1.10 + } 1.11 Symbol descSym = findDescriptorSymbol(targets.head.tsym); 1.12 Type descType = findDescriptorType(targets.head); 1.13 ClassSymbol csym = new ClassSymbol(cflags, name, env.enclClass.sym.outermostClass());
2.1 --- a/src/share/classes/com/sun/tools/javac/comp/Attr.java Thu Jul 25 11:02:27 2013 +0200 2.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java Thu Jul 25 14:47:43 2013 +0100 2.3 @@ -2970,7 +2970,9 @@ 2.4 //check that functional interface class is well-formed 2.5 ClassSymbol csym = types.makeFunctionalInterfaceClass(env, 2.6 names.empty, List.of(fExpr.targets.head), ABSTRACT); 2.7 - chk.checkImplementations(env.tree, csym, csym); 2.8 + if (csym != null) { 2.9 + chk.checkImplementations(env.tree, csym, csym); 2.10 + } 2.11 } 2.12 } 2.13 }
3.1 --- a/src/share/classes/com/sun/tools/javac/comp/Infer.java Thu Jul 25 11:02:27 2013 +0200 3.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Infer.java Thu Jul 25 14:47:43 2013 +0100 3.3 @@ -1240,7 +1240,8 @@ 3.4 CAPTURED(InferenceBound.UPPER) { 3.5 @Override 3.6 public boolean accepts(UndetVar t, InferenceContext inferenceContext) { 3.7 - return !inferenceContext.free(t.getBounds(InferenceBound.UPPER, InferenceBound.LOWER)); 3.8 + return t.isCaptured() && 3.9 + !inferenceContext.free(t.getBounds(InferenceBound.UPPER, InferenceBound.LOWER)); 3.10 } 3.11 3.12 @Override
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 4.2 +++ b/test/tools/javac/lambda/8020804/T8020804.java Thu Jul 25 14:47:43 2013 +0100 4.3 @@ -0,0 +1,46 @@ 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 8020804 4.30 + * @summary javac crashes when speculative attribution infers intersection type with array component 4.31 + * @compile T8020804.java 4.32 + */ 4.33 + 4.34 +import java.util.*; 4.35 + 4.36 +class T8020804 { 4.37 + interface Supplier<D> { 4.38 + D make(); 4.39 + } 4.40 + 4.41 + void m(Object o) { } 4.42 + void m(char[] c) { } 4.43 + 4.44 + <C extends Collection<?>> C g(Supplier<C> sc) { return null; } 4.45 + 4.46 + void test() { 4.47 + m(g(LinkedList<Double>::new)); 4.48 + } 4.49 +}