JDK-8043914 : Inference failure involving capture inference variable
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 9
  • Priority: P3
  • Status: Resolved
  • Resolution: Duplicate
  • Submitted: 2014-05-23
  • Updated: 2014-10-22
  • Resolved: 2014-06-03
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
8u20Resolved
Related Reports
Duplicate :  
Duplicate :  
Relates :  
Description
The following compiles in 8 but fails to compile current in 9:

import java.util.ArrayList;
import java.util.List;

public class CaptureInference {
    public List<String> l;

    public CaptureInference() {
        l = new ArrayList<>(get(String.class));
    }

    public static <T> List<? extends T> get(Class<T> clazz) {
        return null;
    }
}

/*
String.class -> Class<t>
Class<String> -> Class<t>
{ t = String }

List<? extends t> -> Collection<? extends e>
{ t = String, z <: Object, List<z> = capture(List<? extends t>) }
List<z> -> Collection<? extends e>
{ t = String, z <: Object, z <: e, List<z> = capture(List<? extends t>) }

ArrayList<e> -> List<String>
{ t = String, e = String, z <: Object, z <: e, List<z> = capture(List<? extends t>) }
*/

Comments
Ultimately, this arises because a test of the following form fails: I<CAP> <: I<? extends CAP> This is because Types.containsType replaces the capture variable on the left with its upper bound.
03-06-2014

Began failing with fix for JDK-8033718.
28-05-2014

Minimal test: interface I<T> {} <A> I<? extends A> foo(I<A> arg) { return arg; } <B> void bar(I<? extends B> arg) {} void test(I<String> arg) { bar(foo(arg)); }
28-05-2014