JDK-7086601 : Error message bug: cause for method mismatch is 'null'
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 7
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2011-09-02
  • Updated: 2012-02-24
  • 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
Description
Given a method invocation that won't match either of two candidates, I'm getting an error message that prints 'null' where a useful description of the mismatch should go.

Code:
public class CauseError {
<S> Iterable<S> glb(Iterable<? super S> s1, Iterable<? super S> s2) { return null; }
<T> Iterable<T> glb(Iterable<? super T> t) { return null; }

CauseError() {
 glb((Iterable<String>) null, (Iterable<Integer>) null);
}

}

Message:

CauseError.java:6: error: no suitable method found for glb(Iterable<String>,Iterable<Integer>)
 glb((Iterable<String>) null, (Iterable<Integer>) null);
 ^
    method CauseError.<T>glb(Iterable<? super T>) is not applicable
      (cannot instantiate from arguments because actual and formal argument lists differ in length)
    method CauseError.<S>glb(Iterable<? super S>,Iterable<? super S>) is not applicable
      (null) <<<<<<<<<< (SHOULD NOT BE NULL)
  where T,S are type-variables:
    T extends Object declared in method <T>glb(Iterable<? super T>)
    S extends Object declared in method <S>glb(Iterable<? super S>,Iterable<? super S>)

Commenting out the other declaration produces a more useful message:

CauseError.java:6: error: method glb in class CauseError cannot be applied to given types
 glb((Iterable<String>) null, (Iterable<Integer>) null);
 ^
  required: Iterable<? super S>,Iterable<? super S>
  found: Iterable<String>,Iterable<Integer>
  where S is a type-variable:
    S extends Object declared in method <S>glb(Iterable<? super S>,Iterable<? super S>)

Comments
SUGGESTED FIX A webrev of this fix is available at the following URL: http://hg.openjdk.java.net/jdk8/tl/langtools/rev/3a2200681d69
13-09-2011

EVALUATION The code in Infer.minimizeInst doesn't generate any explanation diagnostics in case lub() result is incompatible with the inference variable's upper bounds. This lead to a method resolution diagnostic that has a 'null' in its explanation field.
13-09-2011