JDK-8315134 : javac inference seems to be capturing types incorrectly
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Priority: P3
  • Status: Open
  • Resolution: Unresolved
  • Submitted: 2023-08-28
  • Updated: 2023-08-29
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 22
22Unresolved
Description
when compiling this code:

import java.util.*;

public class Test {
    private static <T> void arrayMethod(List<? super T>[] args) {
        listMethod(Arrays.asList(args));
    }

    private static <T> void listMethod(List<List<? super T>> list) {
    }
}

javac issues error:

Test.java:5: error: method listMethod in class Test cannot be applied to given types;
        listMethod(Arrays.asList(args));
        ^
  required: List<List<? super T#1>>
  found:    List<List<? super T#2>>
  reason: inference variable T#3 has incompatible bounds
    equality constraints: List<? super CAP#1>
    lower bounds: List<? super T#2>
  where T#1,T#2,T#3 are type-variables:
    T#1 extends Object declared in method <T#1>listMethod(List<List<? super T#1>>)
    T#2 extends Object declared in method <T#2>arrayMethod(List<? 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

there seems to be a type capture out of place and probably not blessed by the spec

Reported by Attila Kelemen, see discussion at: https://mail.openjdk.org/pipermail/compiler-dev/2023-August/024034.html
Comments
A pull request was submitted for review. URL: https://git.openjdk.org/jdk/pull/15463 Date: 2023-08-29 03:20:52 +0000
29-08-2023