JDK-8164401 : Incorrect treatment of wildcards in subtyping
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 7u51,8u60,9
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • Submitted: 2016-08-18
  • Updated: 2017-12-07
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_majorUnresolved
Related Reports
Duplicate :  
Relates :  
Description
This compiles but should not. Running produces a CCE.

public class WildSubtyping {
    static class Container<T> {
        T value;
    }

    static class A<T> {
        T aValue;

        void putT(T t) {}
    }

    static class B<T> extends A<A<T>> {
        T bValue;

        @Override
        void putT(A<T> a) {
            bValue = a.aValue;
        }
    }

    static void bar(Container<? extends A<A<?>>> container) {
        A<Integer> a = new A<Integer>();
        a.aValue = 4;
        container.value.putT(a);
    }

    static void foo(Container<B<?>> container) {
        B<String> b = new B<String>();
        container.value = b;
        bar(container); // Container<B<?>> is not subtype of Container<? extends A<A<?>>> !!
        b.bValue.length();
    }

    public static void main(String[] args) {
        foo(new Container<B<?>>());
    }
}

Reported by Ross Tate, as encountered by the Kotlin team.
Comments
Simplified to just highlight the subtyping bug: public class WildSubtyping { interface Container<T> {} interface A<T> {} interface B<T> extends A<A<T>> {} void bar(Container<? extends A<A<?>>> container) {} void foo(Container<B<?>> container) { bar(container); // Container<B<?>> is not subtype of Container<? extends A<A<?>>> !! } }
18-08-2016