# HG changeset patch # User mcimadamore # Date 1316178971 -3600 # Node ID 7f15f5a11ae91601a9ba0bc9e435f901cd0fb9ad # Parent 5dd595ab058ec0c7d69965e1b829104f698588e3 7086586: Inference producing null type argument Summary: Inference should fail in 15.12.2.7 when inference variables with 'nulltype' upper bounds are found Reviewed-by: dlsmith diff -r 5dd595ab058e -r 7f15f5a11ae9 langtools/src/share/classes/com/sun/tools/javac/code/Types.java --- a/langtools/src/share/classes/com/sun/tools/javac/code/Types.java Wed Sep 14 18:26:57 2011 -0700 +++ b/langtools/src/share/classes/com/sun/tools/javac/code/Types.java Fri Sep 16 14:16:11 2011 +0100 @@ -508,8 +508,13 @@ @Override public Boolean visitUndetVar(UndetVar t, Type s) { //todo: test against origin needed? or replace with substitution? - if (t == s || t.qtype == s || s.tag == ERROR || s.tag == UNKNOWN) + if (t == s || t.qtype == s || s.tag == ERROR || s.tag == UNKNOWN) { return true; + } else if (s.tag == BOT) { + //if 's' is 'null' there's no instantiated type U for which + //U <: s (but 'null' itself, which is not a valid type) + return false; + } if (t.inst != null) return isSubtypeNoCapture(t.inst, s); // TODO: ", warn"? diff -r 5dd595ab058e -r 7f15f5a11ae9 langtools/test/tools/javac/Diagnostics/6862608/T6862608a.out --- a/langtools/test/tools/javac/Diagnostics/6862608/T6862608a.out Wed Sep 14 18:26:57 2011 -0700 +++ b/langtools/test/tools/javac/Diagnostics/6862608/T6862608a.out Fri Sep 16 14:16:11 2011 +0100 @@ -1,3 +1,3 @@ -T6862608a.java:19:41: compiler.err.prob.found.req: (compiler.misc.incompatible.types.1: (compiler.misc.infer.no.conforming.instance.exists: T, java.util.Comparator, java.util.Comparator)), java.util.Comparator, java.util.Comparator +T6862608a.java:19:33: compiler.err.cant.apply.symbol.1: kindname.method, compound, java.lang.Iterable>, java.util.List>, kindname.class, T6862608a, (compiler.misc.infer.no.conforming.assignment.exists: T, java.util.List>, java.lang.Iterable>) - compiler.misc.where.description.typevar: T,{(compiler.misc.where.typevar: T, java.lang.Object, kindname.method, compound(java.lang.Iterable>))} 1 error diff -r 5dd595ab058e -r 7f15f5a11ae9 langtools/test/tools/javac/generics/inference/6638712/T6638712a.out --- a/langtools/test/tools/javac/generics/inference/6638712/T6638712a.out Wed Sep 14 18:26:57 2011 -0700 +++ b/langtools/test/tools/javac/generics/inference/6638712/T6638712a.out Fri Sep 16 14:16:11 2011 +0100 @@ -1,2 +1,2 @@ -T6638712a.java:16:41: compiler.err.prob.found.req: (compiler.misc.incompatible.types.1: (compiler.misc.infer.no.conforming.instance.exists: T, java.util.Comparator, java.util.Comparator)), java.util.Comparator, java.util.Comparator +T6638712a.java:16:33: compiler.err.cant.apply.symbol.1: kindname.method, compound, java.lang.Iterable>, java.util.List>, kindname.class, T6638712a, (compiler.misc.infer.no.conforming.assignment.exists: T, java.util.List>, java.lang.Iterable>) 1 error diff -r 5dd595ab058e -r 7f15f5a11ae9 langtools/test/tools/javac/generics/inference/7086586/T7086586.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/generics/inference/7086586/T7086586.java Fri Sep 16 14:16:11 2011 +0100 @@ -0,0 +1,19 @@ +/** + * @test /nodynamiccopyright/ + * @bug 7086586 + * @summary Inference producing null type argument + * @compile/fail/ref=T7086586.out -XDrawDiagnostics T7086586.java + */ +import java.util.List; + +class T7086586 { + + List m(List dummy) { return null; } + + void test(List l) { + String s = m(l).get(0); + Number n = m(l).get(0); + Exception e = m(l).get(0); + m(l).nonExistentMethod(); + } +} diff -r 5dd595ab058e -r 7f15f5a11ae9 langtools/test/tools/javac/generics/inference/7086586/T7086586.out --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/generics/inference/7086586/T7086586.out Fri Sep 16 14:16:11 2011 +0100 @@ -0,0 +1,5 @@ +T7086586.java:14:20: compiler.err.cant.apply.symbol.1: kindname.method, m, java.util.List, java.util.List, kindname.class, T7086586, (compiler.misc.infer.no.conforming.assignment.exists: T, java.util.List, java.util.List) +T7086586.java:15:20: compiler.err.cant.apply.symbol.1: kindname.method, m, java.util.List, java.util.List, kindname.class, T7086586, (compiler.misc.infer.no.conforming.assignment.exists: T, java.util.List, java.util.List) +T7086586.java:16:23: compiler.err.cant.apply.symbol.1: kindname.method, m, java.util.List, java.util.List, kindname.class, T7086586, (compiler.misc.infer.no.conforming.assignment.exists: T, java.util.List, java.util.List) +T7086586.java:17:9: compiler.err.cant.apply.symbol.1: kindname.method, m, java.util.List, java.util.List, kindname.class, T7086586, (compiler.misc.infer.no.conforming.assignment.exists: T, java.util.List, java.util.List) +4 errors diff -r 5dd595ab058e -r 7f15f5a11ae9 langtools/test/tools/javac/generics/inference/7086586/T7086586b.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/generics/inference/7086586/T7086586b.java Fri Sep 16 14:16:11 2011 +0100 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2011, 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 7086586 + * + * @summary Inference producing null type argument + */ +import java.util.List; + +public class T7086586b { + + int assertionCount = 0; + + void assertTrue(boolean cond) { + if (!cond) { + throw new AssertionError(); + } + assertionCount++; + } + + void m(List dummy) { assertTrue(false); } + void m(Object dummy) { assertTrue(true); } + + void test(List l) { + m(l); + assertTrue(assertionCount == 1); + } + + public static void main(String[] args) { + new T7086586b().test(null); + } +}