langtools/test/tools/javac/CaptureInSubtype.java
author katleman
Thu, 21 Aug 2014 14:16:14 -0700
changeset 25878 6d561031123e
parent 24796 f940af3221e2
child 37636 6c6e6e25189d
permissions -rw-r--r--
Added tag jdk9-b27 for changeset 98ce0879ab4c

/*
 * @test /nodynamiccopyright/
 * @bug 5044626
 * @summary type system loophole in wildcard substitution
 * @author Gilad Bracha
 *
 * @compile/fail/ref=CaptureInSubtype.out -XDrawDiagnostics  CaptureInSubtype.java
 */

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

public class CaptureInSubtype {

    static class SuperOfFlaw<S>{
        S s;
        S get() { return s;}
        void put(S a) { s = a;}

        SuperOfFlaw(S a) { s = a;}
    }

    static class Flaw<T> extends SuperOfFlaw<List<T>> {
        List<T> fetch(){return s;}

        Flaw(T t){super(new ArrayList<T>()); s.add(t);}
    }

    static class SuperOfShowFlaw {

        SuperOfFlaw<List<?>> m(){return null;}
    }


    public static class ShowFlaw extends SuperOfShowFlaw {
        static Flaw<Number> fn =  new Flaw<Number>(new Integer(3));

        Flaw<?> m(){return fn;}
    }

    public static void main(String[] args) {
        SuperOfShowFlaw sosf = new ShowFlaw();
        SuperOfFlaw<List<?>> sof = sosf.m();
        List<String> ls = new ArrayList<String>();
        ls.add("Smalltalk rules!");
        sof.put(ls);
        Number n = ShowFlaw.fn.get().get(0);
    }

}