JDK-7086586 : Inference producing null type argument
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 7
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2011-09-02
  • Updated: 2014-03-27
  • Resolved: 2012-02-24
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7 JDK 8
7u4Fixed 8 b08Fixed
Related Reports
Relates :  
Relates :  
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
16-09-2011

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.
07-09-2011