JDK-8155072 : Type inference regression
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 9
  • Priority: P3
  • Status: Resolved
  • Resolution: Duplicate
  • OS: generic
  • CPU: x86_64
  • Submitted: 2016-04-22
  • Updated: 2016-09-09
  • Resolved: 2016-09-09
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.
Other
tbd_majorResolved
Related Reports
Duplicate :  
Relates :  
Relates :  
Relates :  
Description
FULL PRODUCT VERSION :
java full version "9-ea+114"


ADDITIONAL OS VERSION INFORMATION :
 x86_64 GNU/Linux

A DESCRIPTION OF THE PROBLEM :
The attach program is accepted by the JDK 8 javac, but rejected by the JDK 9 javac.

REGRESSION.  Last worked in version 8u92

ADDITIONAL REGRESSION INFORMATION: 
java full version "1.8.0_92-b14"

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
$ javac Test.java

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I expected the compilation to succeed.
ACTUAL -
The compilation failed.

ERROR MESSAGES/STACK TRACES THAT OCCUR :
Test.java:7: error: method m in class Test cannot be applied to given types;
    m(Arrays.asList(cs));
    ^
  required: Iterable<? extends Test.C<? super T#1>>
  found: List<Test.C<? super T#2>>
  reason: inference variable T#3 has incompatible bounds
    upper bounds: Test.C<? super CAP#1>,Object
    lower bounds: Test.C<? super T#2>
  where T#1,T#2,T#3 are type-variables:
    T#1 extends Object declared in method <T#1>m(Iterable<? extends Test.C<? super T#1>>)
    T#2 extends Object declared in method <T#2>t(Test.C<? super T#2>...)
    T#3 extends Object declared in method <T#3>asList(T#3...)
  where CAP#1 is a fresh type-variable:
    CAP#1 extends Object super: T#2 from capture of ? super T#2
Note: Test.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
1 error


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.util.Arrays;
class Test {
  public class C<T> {}
  public static <T> void m(Iterable<? extends C<? super T>> cs) {}
  public static <T> void t(C<? super T>... cs) {
    m(Arrays.<C<? super T>>asList(cs));
    m(Arrays.asList(cs));
  }
}

---------- END SOURCE ----------


Comments
See JDK-8016196 for the underlying specification issue: how do we do inference without introducing new capture variables? See JDK-8160114 for a similar example���javac behavior is different, but the comments discuss some of the underlying issues.
18-08-2016

Not a *duplicate* of JDK-8033718, but began failing at that point because the issue was being masked by another bug.
18-08-2016

Likely a duplicate of JDK-8033718 (regression started in 9b13).
17-08-2016

This code gets compiled in 8u92 but gives compilation error in 9 ea b115. == -sh-4.1$ /opt/java/jdk1.8.0_92/bin/javac -Xlint Test.java Test.java:5: warning: [unchecked] Possible heap pollution from parameterized vararg type Test.C<? super T> public static <T> void t(C<? super T>... cs) { ^ where T is a type-variable: T extends Object declared in method <T>t(Test.C<? super T>...) 1 warning -sh-4.1$ ls Test$C.class Test.class Test.java -sh-4.1$ -sh-4.1$ /opt/java/jdk-9_ea-115/bin/javac -Xlint Test.java Test.java:5: warning: [unchecked] Possible heap pollution from parameterized vararg type Test.C<? super T> public static <T> void t(C<? super T>... cs) { ^ where T is a type-variable: T extends Object declared in method <T>t(Test.C<? super T>...) Test.java:7: error: method m in class Test cannot be applied to given types; m(Arrays.asList(cs)); ^ required: Iterable<? extends Test.C<? super T#1>> found: List<Test.C<? super T#2>> reason: inference variable T#3 has incompatible bounds upper bounds: Test.C<? super CAP#1>,Object lower bounds: Test.C<? super T#2> where T#1,T#2,T#3 are type-variables: T#1 extends Object declared in method <T#1>m(Iterable<? extends Test.C<? super T#1>>) T#2 extends Object declared in method <T#2>t(Test.C<? super T#2>...) T#3 extends Object declared in method <T#3>asList(T#3...) where CAP#1 is a fresh type-variable: CAP#1 extends Object super: T#2 from capture of ? super T#2 1 error 1 warning ==
26-04-2016