1 public class test_instance_subtype_violated {
3 public static void main(String[] args) {
4 TestController ct = new TestController();
6 TestLoader ld1 = new TestLoader(ClassLoader.getSystemClassLoader(), "ld1", ct);
7 TestLoader ld2 = new TestLoader(ClassLoader.getSystemClassLoader(), "ld2", ct);
8 TestLoader ld3 = new TestLoader(ClassLoader.getSystemClassLoader(), "ld3", ct);
10 ld1.addClassfile("BarUseFoo", "classes1/BarUseFoo.class");
11 ld1.addClassfile("Foo", "classes1/Foo.class");
12 ld1.addParentDelegation("java.lang.Object");
13 ld1.addParentDelegation("java.lang.String");
15 ld2.addClassfile("BarPassFoo", "classes2/BarPassFoo.class");
16 ld2.addDelegation("BarUseFoo", ld1);
17 ld2.addDelegation("Foo", ld1);
18 ld2.addDelegation("DerivedFoo", ld3);
19 ld2.addParentDelegation("java.lang.Object");
20 ld2.addParentDelegation("java.lang.String");
22 ld3.addClassfile("Foo", "classes3/Foo.class");
23 ld3.addClassfile("DerivedFoo", "classes3/DerivedFoo.class");
24 ld3.addParentDelegation("java.lang.Object");
25 ld3.addParentDelegation("java.lang.String");
28 // loading and linking BarPassFoo
29 ct.expect("requested", ld2, "BarPassFoo");
30 ct.expectLoadFromSystem(ld2, "java.lang.Object");
31 ct.expect("defined", ld2, "<BarPassFoo>");
32 ct.expect("loaded", ld2, "<BarPassFoo>");
34 Class cls = ct.loadClass(ld2, "BarPassFoo");
36 // executing BarPassFoo.passDerivedFooInstance: new DerivedFoo
37 ct.expectDelegation(ld2, ld3, "DerivedFoo");
39 // linking (ld3, DerivedFoo)
40 ct.expect("requested", ld3, "Foo");
41 ct.expectLoadFromSystem(ld3, "java.lang.Object");
42 ct.expect("defined", ld3, "<Foo>");
43 ct.expectDelegationDefinition(ld2, ld3, "DerivedFoo");
45 // resolving Foo.virtualId
46 // the deferred subtype check ((ld2, DerivedFoo) subtypeof (ld2, Foo)) is done
47 ct.expectDelegation(ld2, ld1, "Foo");
48 // ...linking (ld2, Foo) == (ld1, Foo)
49 ct.expectLoadFromSystem(ld1, "java.lang.Object");
50 ct.expectDelegationDefinition(ld2, ld1, "Foo");
52 // the subtype constraint ((ld2, DerivedFoo) subtypeof (ld2, Foo)) is violated
53 ct.expect("exception", "java.lang.LinkageError", "<BarPassFoo>");
55 ct.checkStringGetterMustFail(cls, "passDerivedFooInstance");