JDK-8056014 : Type inference may be skipped for a complex receiver generic method in a parameter position
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 8u20
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: linux
  • CPU: x86_64
  • Submitted: 2014-08-25
  • Updated: 2015-06-04
  • Resolved: 2014-09-08
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 8 JDK 9
8u40Fixed 9 b31Fixed
Related Reports
Duplicate :  
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.8.0_20"
Java(TM) SE Runtime Environment (build 1.8.0_20-b26)
Java HotSpot(TM) 64-Bit Server VM (build 25.20-b23, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Kubuntu 14.04 x64

A DESCRIPTION OF THE PROBLEM :
This works in jdk1.8.0_11 and in Eclipse but not anymore in jdk1.8.0_20:

public class Testbed {
	public static void main(String[] args) {
		java.util.List<Dog> l = null;
		Dog d = l.get(0).copy(); // ok
		foo(l.get(0).copy()); // error
	}

	private static void foo(Dog d) { }
}

class Animal {
	public <T> T copy() {
		return null;
	}
}

class Dog extends Animal {
}


jdk1.8.0_20 message:

Testbed.java:5: error: method foo in class Testbed cannot be applied to given types;
                foo(l.get(0).copy()); // error
                ^
  required: Dog
  found: Object
  reason: argument mismatch; Object cannot be converted to Dog
1 error

REGRESSION.  Last worked in version 8u11

ADDITIONAL REGRESSION INFORMATION: 
java version "1.8.0_11"
Java(TM) SE Runtime Environment (build 1.8.0_11-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.11-b03, mixed mode)

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Try to compile the given snippet.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
It compiles.
ACTUAL -
Syntax error message.

ERROR MESSAGES/STACK TRACES THAT OCCUR :
Testbed.java:5: error: method foo in class Testbed cannot be applied to given types;
                foo(l.get(0).copy()); // error
                ^
  required: Dog
  found: Object
  reason: argument mismatch; Object cannot be converted to Dog
1 error

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
public class Testbed {
	public static void main(String[] args) {
		java.util.List<Dog> l = null;
		Dog d = l.get(0).copy(); // ok
		foo(l.get(0).copy()); // error
	}

	private static void foo(Dog d) { }
}

class Animal {
	public <T> T copy() {
		return null;
	}
}

class Dog extends Animal {
}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Use jdk1.8.0_11 and be sad.


Comments
This simplification succeeds: Dog d1 = null; foo(d1.copy()); // compiles Since 'l.get(0)' is a standalone expression of type 'Dog', it should be interchangeable with 'd1'.
29-08-2014