From 567f352cb3a3ae95e4ce550e214f2f06c49413f6 Mon Sep 17 00:00:00 2001 From: mcimadamore Date: Thu, 25 Jul 2013 14:47:43 +0100 Subject: [PATCH] 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 --- .../com/sun/tools/javac/code/Types.java | 4 +- .../com/sun/tools/javac/comp/Attr.java | 4 +- .../com/sun/tools/javac/comp/Infer.java | 3 +- test/tools/javac/lambda/8020804/T8020804.java | 46 +++++++++++++++++++ 4 files changed, 54 insertions(+), 3 deletions(-) create mode 100644 test/tools/javac/lambda/8020804/T8020804.java diff --git a/src/share/classes/com/sun/tools/javac/code/Types.java b/src/share/classes/com/sun/tools/javac/code/Types.java index e4cf5830..e1887b5f 100644 --- a/src/share/classes/com/sun/tools/javac/code/Types.java +++ b/src/share/classes/com/sun/tools/javac/code/Types.java @@ -620,7 +620,9 @@ public class Types { * (ii) perform functional interface bridge calculation. */ public ClassSymbol makeFunctionalInterfaceClass(Env env, Name name, List targets, long cflags) { - Assert.check(targets.nonEmpty() && isFunctionalInterface(targets.head)); + if (targets.isEmpty() || !isFunctionalInterface(targets.head)) { + return null; + } Symbol descSym = findDescriptorSymbol(targets.head.tsym); Type descType = findDescriptorType(targets.head); ClassSymbol csym = new ClassSymbol(cflags, name, env.enclClass.sym.outermostClass()); diff --git a/src/share/classes/com/sun/tools/javac/comp/Attr.java b/src/share/classes/com/sun/tools/javac/comp/Attr.java index 1c33d306..4ff6f178 100644 --- a/src/share/classes/com/sun/tools/javac/comp/Attr.java +++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java @@ -2970,7 +2970,9 @@ public class Attr extends JCTree.Visitor { //check that functional interface class is well-formed ClassSymbol csym = types.makeFunctionalInterfaceClass(env, names.empty, List.of(fExpr.targets.head), ABSTRACT); - chk.checkImplementations(env.tree, csym, csym); + if (csym != null) { + chk.checkImplementations(env.tree, csym, csym); + } } } } diff --git a/src/share/classes/com/sun/tools/javac/comp/Infer.java b/src/share/classes/com/sun/tools/javac/comp/Infer.java index ebc6867a..a87156a6 100644 --- a/src/share/classes/com/sun/tools/javac/comp/Infer.java +++ b/src/share/classes/com/sun/tools/javac/comp/Infer.java @@ -1240,7 +1240,8 @@ public class Infer { CAPTURED(InferenceBound.UPPER) { @Override public boolean accepts(UndetVar t, InferenceContext inferenceContext) { - return !inferenceContext.free(t.getBounds(InferenceBound.UPPER, InferenceBound.LOWER)); + return t.isCaptured() && + !inferenceContext.free(t.getBounds(InferenceBound.UPPER, InferenceBound.LOWER)); } @Override diff --git a/test/tools/javac/lambda/8020804/T8020804.java b/test/tools/javac/lambda/8020804/T8020804.java new file mode 100644 index 00000000..ce8b98e6 --- /dev/null +++ b/test/tools/javac/lambda/8020804/T8020804.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8020804 + * @summary javac crashes when speculative attribution infers intersection type with array component + * @compile T8020804.java + */ + +import java.util.*; + +class T8020804 { + interface Supplier { + D make(); + } + + void m(Object o) { } + void m(char[] c) { } + + > C g(Supplier sc) { return null; } + + void test() { + m(g(LinkedList::new)); + } +} -- GitLab