1/*
2 * @test /nodynamiccopyright/
3 * @bug 5044626
4 * @summary type system loophole in wildcard substitution
5 * @author Gilad Bracha
6 *
7 * @compile/fail/ref=CaptureInSubtype.out -XDrawDiagnostics  CaptureInSubtype.java
8 */
9
10import java.util.List;
11import java.util.ArrayList;
12
13public class CaptureInSubtype {
14
15    static class SuperOfFlaw<S>{
16        S s;
17        S get() { return s;}
18        void put(S a) { s = a;}
19
20        SuperOfFlaw(S a) { s = a;}
21    }
22
23    static class Flaw<T> extends SuperOfFlaw<List<T>> {
24        List<T> fetch(){return s;}
25
26        Flaw(T t){super(new ArrayList<T>()); s.add(t);}
27    }
28
29    static class SuperOfShowFlaw {
30
31        SuperOfFlaw<List<?>> m(){return null;}
32    }
33
34
35    public static class ShowFlaw extends SuperOfShowFlaw {
36        static Flaw<Number> fn =  new Flaw<Number>(Integer.valueOf(3));
37
38        Flaw<?> m(){return fn;}
39    }
40
41    public static void main(String[] args) {
42        SuperOfShowFlaw sosf = new ShowFlaw();
43        SuperOfFlaw<List<?>> sof = sosf.m();
44        List<String> ls = new ArrayList<String>();
45        ls.add("Smalltalk rules!");
46        sof.put(ls);
47        Number n = ShowFlaw.fn.get().get(0);
48    }
49
50}
51