United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: 7086586 Inference producing null type argument
7086586 : Inference producing null type argument

Details
Type:
Bug
Submit Date:
2011-09-02
Status:
Closed
Updated Date:
2012-02-24
Project Name:
JDK
Resolved Date:
2012-02-24
Component:
tools
OS:
generic
Sub-Component:
javac
CPU:
generic
Priority:
P4
Resolution:
Fixed
Affected Versions:
7
Fixed Versions:
8

Related Reports
Backport:
Relates:
Relates:

Sub Tasks

Description
When the inference algorithm determines that an inference variable is a subtype of a capture variable without a lower bound, it may choose "null" as the inference result.  This is inconsistent with specified behavior.

<T> Iterable<T> empty(Iterable<? super T> dummy) { return null; }
{
String s = empty((Iterable<?>) null).iterator().next();    // no error reported
Number n = empty((Iterable<?>) null).iterator().next();    // no error reported
Exception e = empty((Iterable<?>) null).iterator().next(); // no error reported
empty((Iterable<?>) null).foo(); // error: can't find in Iterable<<null>>
}

                                    

Comments
SUGGESTED FIX

A webrev of this fix is available at the following URL:
http://hg.openjdk.java.net/jdk8/tl/langtools/rev/c0835c8489b0
                                     
2011-09-16
EVALUATION

This problem has been caused by the fix of 6650759. In that fix, we augmented type-inference so that constraints generated during 15.12.2.7 were propagated to 15.12.2.8 (esp. upper bounds and equality constraints). Unfortunately, since javac sometimes produces 'nulltype' as the upper bound of an inference variable, it is sometime possible that the 'nulltype' itself is choosen as the inferred type during 15.12.2.8.

This behavior is not conformant w.r.t. the JLS and therefore should be addressed: nulltype constraints should never be propagated - or actively used by javac.
                                     
2011-09-07



Hardware and Software, Engineered to Work Together