jdk/test/jdk/lambda/vm/DefaultMethodsTest.java
changeset 21507 624a61211dd7
parent 21506 115e1128ce1a
parent 21474 4d9ae2ec8ba6
child 21508 3dd9732b1703
equal deleted inserted replaced
21506:115e1128ce1a 21507:624a61211dd7
     1 /*
       
     2  * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.
       
     8  *
       
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    12  * version 2 for more details (a copy is included in the LICENSE file that
       
    13  * accompanied this code).
       
    14  *
       
    15  * You should have received a copy of the GNU General Public License version
       
    16  * 2 along with this work; if not, write to the Free Software Foundation,
       
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    18  *
       
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    20  * or visit www.oracle.com if you need additional information or have any
       
    21  * questions.
       
    22  */
       
    23 
       
    24 package vm;
       
    25 
       
    26 import java.lang.reflect.*;
       
    27 import java.util.*;
       
    28 import java.io.File;
       
    29 import java.io.IOException;
       
    30 
       
    31 import org.testng.annotations.Test;
       
    32 import separate.*;
       
    33 import separate.Compiler;
       
    34 
       
    35 import static org.testng.Assert.*;
       
    36 import static separate.SourceModel.*;
       
    37 import static separate.SourceModel.Class;
       
    38 
       
    39 @Test(groups = "vm")
       
    40 public class DefaultMethodsTest extends TestHarness {
       
    41     public DefaultMethodsTest() {
       
    42         super(false, false);
       
    43     }
       
    44 
       
    45     /**
       
    46      * class C { public int m() { return 22; } }
       
    47      *
       
    48      * TEST: C c = new C(); c.m() == 22
       
    49      */
       
    50     public void testHarnessInvokeVirtual() {
       
    51         Class C = new Class("C", ConcreteMethod.std("22"));
       
    52         assertInvokeVirtualEquals(22, C);
       
    53     }
       
    54 
       
    55     /**
       
    56      * interface I { int m(); }
       
    57      * class C implements I { public int m() { return 33; } }
       
    58      *
       
    59      * TEST: I i = new C(); i.m() == 33;
       
    60      */
       
    61     public void testHarnessInvokeInterface() {
       
    62         Interface I = new Interface("I", AbstractMethod.std());
       
    63         Class C = new Class("C", I, ConcreteMethod.std("33"));
       
    64         assertInvokeInterfaceEquals(33, C, I);
       
    65     }
       
    66 
       
    67     /**
       
    68      * class C {}
       
    69      *
       
    70      * TEST: C c = new C(); c.m() throws NoSuchMethod
       
    71      */
       
    72     public void testHarnessThrows() {
       
    73         Class C = new Class("C");
       
    74         assertThrows(NoSuchMethodError.class, C);
       
    75     }
       
    76 
       
    77     /**
       
    78      * interface I { int m() default { return 44; } }
       
    79      * class C implements I {}
       
    80      *
       
    81      * TEST: C c = new C(); c.m() == 44;
       
    82      * TEST: I i = new C(); i.m() == 44;
       
    83      */
       
    84     public void testBasicDefault() {
       
    85         Interface I = new Interface("I", DefaultMethod.std("44"));
       
    86         Class C = new Class("C", I);
       
    87 
       
    88         assertInvokeVirtualEquals(44, C);
       
    89         assertInvokeInterfaceEquals(44, C, I);
       
    90     }
       
    91 
       
    92     /**
       
    93      * interface I { default int m() { return 44; } }
       
    94      * interface J extends I {}
       
    95      * interface K extends J {}
       
    96      * class C implements K {}
       
    97      *
       
    98      * TEST: C c = new C(); c.m() == 44;
       
    99      * TEST: I i = new C(); i.m() == 44;
       
   100      */
       
   101     public void testFarDefault() {
       
   102         Interface I = new Interface("I", DefaultMethod.std("44"));
       
   103         Interface J = new Interface("J", I);
       
   104         Interface K = new Interface("K", J);
       
   105         Class C = new Class("C", K);
       
   106 
       
   107         assertInvokeVirtualEquals(44, C);
       
   108         assertInvokeInterfaceEquals(44, C, K);
       
   109     }
       
   110 
       
   111     /**
       
   112      * interface I { int m(); }
       
   113      * interface J extends I { default int m() { return 44; } }
       
   114      * interface K extends J {}
       
   115      * class C implements K {}
       
   116      *
       
   117      * TEST: C c = new C(); c.m() == 44;
       
   118      * TEST: K k = new C(); k.m() == 44;
       
   119      */
       
   120     public void testOverrideAbstract() {
       
   121         Interface I = new Interface("I", AbstractMethod.std());
       
   122         Interface J = new Interface("J", I, DefaultMethod.std("44"));
       
   123         Interface K = new Interface("K", J);
       
   124         Class C = new Class("C", K);
       
   125 
       
   126         assertInvokeVirtualEquals(44, C);
       
   127         assertInvokeInterfaceEquals(44, C, K);
       
   128     }
       
   129 
       
   130     /**
       
   131      * interface I { int m() default { return 44; } }
       
   132      * class C implements I { public int m() { return 55; } }
       
   133      *
       
   134      * TEST: C c = new C(); c.m() == 55;
       
   135      * TEST: I i = new C(); i.m() == 55;
       
   136      */
       
   137     public void testExisting() {
       
   138         Interface I = new Interface("I", DefaultMethod.std("44"));
       
   139         Class C = new Class("C", I, ConcreteMethod.std("55"));
       
   140 
       
   141         assertInvokeVirtualEquals(55, C);
       
   142         assertInvokeInterfaceEquals(55, C, I);
       
   143     }
       
   144 
       
   145     /**
       
   146      * interface I { default int m() { return 99; } }
       
   147      * class B implements I {}
       
   148      * class C extends B {}
       
   149      *
       
   150      * TEST: C c = new C(); c.m() == 99;
       
   151      * TEST: I i = new C(); i.m() == 99;
       
   152      */
       
   153     public void testInherited() {
       
   154         Interface I = new Interface("I", DefaultMethod.std("99"));
       
   155         Class B = new Class("B", I);
       
   156         Class C = new Class("C", B);
       
   157 
       
   158         assertInvokeVirtualEquals(99, C);
       
   159         assertInvokeInterfaceEquals(99, C, I);
       
   160     }
       
   161 
       
   162     /**
       
   163      * interface I { default int m() { return 99; } }
       
   164      * class C { public int m() { return 11; } }
       
   165      * class D extends C implements I {}
       
   166      *
       
   167      * TEST: D d = new D(); d.m() == 11;
       
   168      * TEST: I i = new D(); i.m() == 11;
       
   169      */
       
   170     public void testExistingInherited() {
       
   171         Interface I = new Interface("I", DefaultMethod.std("99"));
       
   172         Class C = new Class("C", ConcreteMethod.std("11"));
       
   173         Class D = new Class("D", C, I);
       
   174 
       
   175         assertInvokeVirtualEquals(11, D);
       
   176         assertInvokeInterfaceEquals(11, D, I);
       
   177     }
       
   178 
       
   179     /**
       
   180      * interface I { default int m() { return 44; } }
       
   181      * class C implements I { public int m() { return 11; } }
       
   182      * class D extends C { public int m() { return 22; } }
       
   183      *
       
   184      * TEST: D d = new D(); d.m() == 22;
       
   185      * TEST: I i = new D(); i.m() == 22;
       
   186      */
       
   187     void testExistingInheritedOverride() {
       
   188         Interface I = new Interface("I", DefaultMethod.std("99"));
       
   189         Class C = new Class("C", I, ConcreteMethod.std("11"));
       
   190         Class D = new Class("D", C, ConcreteMethod.std("22"));
       
   191 
       
   192         assertInvokeVirtualEquals(22, D);
       
   193         assertInvokeInterfaceEquals(22, D, I);
       
   194     }
       
   195 
       
   196     /**
       
   197      * interface I { default int m() { return 99; } }
       
   198      * interface J { defaultint m() { return 88; } }
       
   199      * class C implements I { public int m() { return 11; } }
       
   200      * class D extends C { public int m() { return 22; } }
       
   201      * class E extends D implements J {}
       
   202      *
       
   203      * TEST: E e = new E(); e.m() == 22;
       
   204      * TEST: J j = new E(); j.m() == 22;
       
   205      */
       
   206     public void testExistingInheritedPlusDefault() {
       
   207         Interface I = new Interface("I", DefaultMethod.std("99"));
       
   208         Interface J = new Interface("J", DefaultMethod.std("88"));
       
   209         Class C = new Class("C", I, ConcreteMethod.std("11"));
       
   210         Class D = new Class("D", C, ConcreteMethod.std("22"));
       
   211         Class E = new Class("E", D, J);
       
   212 
       
   213         assertInvokeVirtualEquals(22, E);
       
   214         assertInvokeInterfaceEquals(22, E, J);
       
   215     }
       
   216 
       
   217     /**
       
   218      * interface I { default int m() { return 99; } }
       
   219      * class B implements I {}
       
   220      * class C extends B { public int m() { return 77; } }
       
   221      *
       
   222      * TEST: C c = new C(); c.m() == 77;
       
   223      * TEST: I i = new C(); i.m() == 77;
       
   224      */
       
   225     public void testInheritedWithConcrete() {
       
   226         Interface I = new Interface("I", DefaultMethod.std("99"));
       
   227         Class B = new Class("B", I);
       
   228         Class C = new Class("C", B, ConcreteMethod.std("77"));
       
   229 
       
   230         assertInvokeVirtualEquals(77, C);
       
   231         assertInvokeInterfaceEquals(77, C, I);
       
   232     }
       
   233 
       
   234     /**
       
   235      * interface I { default int m() { return 99; } }
       
   236      * class B implements I {}
       
   237      * class C extends B implements I { public int m() { return 66; } }
       
   238      *
       
   239      * TEST: C c = new C(); c.m() == 66;
       
   240      * TEST: I i = new C(); i.m() == 66;
       
   241      */
       
   242     public void testInheritedWithConcreteAndImpl() {
       
   243         Interface I = new Interface("I", DefaultMethod.std("99"));
       
   244         Class B = new Class("B", I);
       
   245         Class C = new Class("C", B, I, ConcreteMethod.std("66"));
       
   246 
       
   247         assertInvokeVirtualEquals(66, C);
       
   248         assertInvokeInterfaceEquals(66, C, I);
       
   249     }
       
   250 
       
   251     /**
       
   252      * interface I { default int m() { return 99; } }
       
   253      * interface J { default int m() { return 88; } }
       
   254      * class C implements I, J {}
       
   255      *
       
   256      * TEST: C c = new C(); c.m() throws AME
       
   257      */
       
   258     public void testConflict() {
       
   259         // debugTest();
       
   260         Interface I = new Interface("I", DefaultMethod.std("99"));
       
   261         Interface J = new Interface("J", DefaultMethod.std("88"));
       
   262         Class C = new Class("C", I, J);
       
   263 
       
   264         assertThrows(AbstractMethodError.class, C);
       
   265     }
       
   266 
       
   267     /**
       
   268      * interface I { int m(); }
       
   269      * interface J { default int m() { return 88; } }
       
   270      * class C implements I, J {}
       
   271      *
       
   272      * TEST: C c = new C(); c.m() throws AME
       
   273      */
       
   274     public void testAmbiguousReabstract() {
       
   275         Interface I = new Interface("I", AbstractMethod.std());
       
   276         Interface J = new Interface("J", DefaultMethod.std("88"));
       
   277         Class C = new Class("C", I, J);
       
   278 
       
   279         assertThrows(AbstractMethodError.class, C);
       
   280     }
       
   281 
       
   282     /**
       
   283      * interface I { default int m() { return 99; } }
       
   284      * interface J extends I { }
       
   285      * interface K extends I { }
       
   286      * class C implements J, K {}
       
   287      *
       
   288      * TEST: C c = new C(); c.m() == 99
       
   289      * TEST: J j = new C(); j.m() == 99
       
   290      * TEST: K k = new C(); k.m() == 99
       
   291      * TEST: I i = new C(); i.m() == 99
       
   292      */
       
   293     public void testDiamond() {
       
   294         Interface I = new Interface("I", DefaultMethod.std("99"));
       
   295         Interface J = new Interface("J", I);
       
   296         Interface K = new Interface("K", I);
       
   297         Class C = new Class("C", J, K);
       
   298 
       
   299         assertInvokeVirtualEquals(99, C);
       
   300         assertInvokeInterfaceEquals(99, C, J);
       
   301         assertInvokeInterfaceEquals(99, C, K);
       
   302         assertInvokeInterfaceEquals(99, C, I);
       
   303     }
       
   304 
       
   305     /**
       
   306      * interface I { default int m() { return 99; } }
       
   307      * interface J extends I { }
       
   308      * interface K extends I { }
       
   309      * interface L extends I { }
       
   310      * interface M extends I { }
       
   311      * class C implements I, J, K, L, M {}
       
   312      *
       
   313      * TEST: C c = new C(); c.m() == 99
       
   314      * TEST: J j = new C(); j.m() == 99
       
   315      * TEST: K k = new C(); k.m() == 99
       
   316      * TEST: I i = new C(); i.m() == 99
       
   317      * TEST: L l = new C(); l.m() == 99
       
   318      * TEST: M m = new C(); m.m() == 99
       
   319      */
       
   320     public void testExpandedDiamond() {
       
   321         Interface I = new Interface("I", DefaultMethod.std("99"));
       
   322         Interface J = new Interface("J", I);
       
   323         Interface K = new Interface("K", I);
       
   324         Interface L = new Interface("L", I);
       
   325         Interface M = new Interface("M", L);
       
   326         Class C = new Class("C", I, J, K, L, M);
       
   327 
       
   328         assertInvokeVirtualEquals(99, C);
       
   329         assertInvokeInterfaceEquals(99, C, J);
       
   330         assertInvokeInterfaceEquals(99, C, K);
       
   331         assertInvokeInterfaceEquals(99, C, I);
       
   332         assertInvokeInterfaceEquals(99, C, L);
       
   333         assertInvokeInterfaceEquals(99, C, M);
       
   334     }
       
   335 
       
   336     /**
       
   337      * interface I { int m() default { return 99; } }
       
   338      * interface J extends I { int m(); }
       
   339      * class C implements J {}
       
   340      *
       
   341      * TEST: C c = new C(); c.m() throws AME
       
   342      */
       
   343     public void testReabstract() {
       
   344         Interface I = new Interface("I", DefaultMethod.std("99"));
       
   345         Interface J = new Interface("J", I, AbstractMethod.std());
       
   346         Class C = new Class("C", J);
       
   347 
       
   348         assertThrows(AbstractMethodError.class, C);
       
   349     }
       
   350 
       
   351     /**
       
   352      * interface I { default int m() { return 88; } }
       
   353      * interface J extends I { default int m() { return 99; } }
       
   354      * class C implements J {}
       
   355      *
       
   356      * TEST: C c = new C(); c.m() == 99;
       
   357      * TEST: J j = new C(); j.m() == 99;
       
   358      * TEST: I i = new C(); i.m() == 99;
       
   359      */
       
   360     public void testShadow() {
       
   361         Interface I = new Interface("I", DefaultMethod.std("88"));
       
   362         Interface J = new Interface("J", I, DefaultMethod.std("99"));
       
   363         Class C = new Class("C", J);
       
   364 
       
   365         assertInvokeVirtualEquals(99, C);
       
   366         assertInvokeInterfaceEquals(99, C, J);
       
   367         assertInvokeInterfaceEquals(99, C, I);
       
   368     }
       
   369 
       
   370     /**
       
   371      * interface I { default int m() { return 88; } }
       
   372      * interface J extends I { default int m() { return 99; } }
       
   373      * class C implements I, J {}
       
   374      *
       
   375      * TEST: C c = new C(); c.m() == 99;
       
   376      * TEST: J j = new C(); j.m() == 99;
       
   377      * TEST: I i = new C(); i.m() == 99;
       
   378      */
       
   379     public void testDisqualified() {
       
   380         Interface I = new Interface("I", DefaultMethod.std("88"));
       
   381         Interface J = new Interface("J", I, DefaultMethod.std("99"));
       
   382         Class C = new Class("C", I, J);
       
   383 
       
   384         assertInvokeVirtualEquals(99, C);
       
   385         assertInvokeInterfaceEquals(99, C, J);
       
   386         assertInvokeInterfaceEquals(99, C, I);
       
   387     }
       
   388 
       
   389     /**
       
   390      * interface I { default int m() { return 99; } }
       
   391      * class C implements I {}
       
   392      *
       
   393      * TEST: C.class.getMethod("m").invoke(new C()) == 99
       
   394      */
       
   395     public void testReflectCall() {
       
   396         Interface I = new Interface("I", DefaultMethod.std("99"));
       
   397         //workaround accessibility issue when loading C with DirectedClassLoader
       
   398         I.addAccessFlag(AccessFlag.PUBLIC);
       
   399         Class C = new Class("C", I);
       
   400 
       
   401         Compiler.Flags[] flags = this.verbose ?
       
   402             new Compiler.Flags[] { Compiler.Flags.VERBOSE } :
       
   403             new Compiler.Flags[] {};
       
   404         Compiler compiler = new Compiler(flags);
       
   405         java.lang.Class<?> cls = null;
       
   406         try {
       
   407             cls = compiler.compileAndLoad(C);
       
   408         } catch (ClassNotFoundException e) {
       
   409             fail("Could not load class");
       
   410         }
       
   411 
       
   412         java.lang.reflect.Method method = null;
       
   413         try {
       
   414             method = cls.getMethod(stdMethodName);
       
   415         } catch (NoSuchMethodException e) {
       
   416             fail("Could not find method in class");
       
   417         }
       
   418         assertNotNull(method);
       
   419 
       
   420         Object c = null;
       
   421         try {
       
   422             c = cls.newInstance();
       
   423         } catch (InstantiationException | IllegalAccessException e) {
       
   424             fail("Could not create instance of class");
       
   425         }
       
   426         assertNotNull(c);
       
   427 
       
   428         Integer res = null;
       
   429         try {
       
   430             res = (Integer)method.invoke(c);
       
   431         } catch (IllegalAccessException |
       
   432                  java.lang.reflect.InvocationTargetException e) {
       
   433             fail("Could not invoke default instance method");
       
   434         }
       
   435         assertNotNull(res);
       
   436 
       
   437         assertEquals(res.intValue(), 99);
       
   438 
       
   439         compiler.cleanup();
       
   440     }
       
   441 
       
   442 
       
   443     /**
       
   444      * interface J { default int m() { return 88; } }
       
   445      * interface I extends J { default int m() { return J.super.m(); } }
       
   446      * class C implements I {}
       
   447      *
       
   448      * TEST: C c = new C(); c.m() == 88;
       
   449      * TEST: I i = new C(); i.m() == 88;
       
   450      */
       
   451     public void testSuperBasic() {
       
   452         // debugTest();
       
   453 
       
   454         Interface J = new Interface("J", DefaultMethod.std("88"));
       
   455         Interface I = new Interface("I", J, new DefaultMethod(
       
   456             "int", stdMethodName, "return J.super.m();"));
       
   457         I.addCompilationDependency(J.findMethod(stdMethodName));
       
   458         Class C = new Class("C", I);
       
   459 
       
   460         assertInvokeVirtualEquals(88, C);
       
   461         assertInvokeInterfaceEquals(88, C, I);
       
   462     }
       
   463 
       
   464     /**
       
   465      * interface K { int m() default { return 99; } }
       
   466      * interface L { int m() default { return 101; } }
       
   467      * interface J extends K, L {}
       
   468      * interface I extends J, K { int m() default { J.super.m(); } }
       
   469      * class C implements I {}
       
   470      *
       
   471      * TEST: C c = new C(); c.m() throws AME
       
   472      * TODO: add case for K k = new C(); k.m() throws AME
       
   473      */
       
   474     public void testSuperConflict() {
       
   475         // debugTest();
       
   476 
       
   477         Interface K = new Interface("K", DefaultMethod.std("99"));
       
   478         Interface L = new Interface("L", DefaultMethod.std("101"));
       
   479         Interface J = new Interface("J", K, L);
       
   480         Interface I = new Interface("I", J, K, new DefaultMethod(
       
   481             "int", stdMethodName, "return J.super.m();"));
       
   482         Interface Jstub = new Interface("J", DefaultMethod.std("-1"));
       
   483         I.addCompilationDependency(Jstub);
       
   484         I.addCompilationDependency(Jstub.findMethod(stdMethodName));
       
   485         Class C = new Class("C", I);
       
   486 
       
   487         assertThrows(AbstractMethodError.class, C);
       
   488     }
       
   489 
       
   490     /**
       
   491      * interface I { default int m() { return 99; } }
       
   492      * interface J extends I { default int m() { return 55; } }
       
   493      * class C implements I, J { public int m() { return I.super.m(); } }
       
   494      *
       
   495      * TEST: C c = new C(); c.m() throws AME
       
   496      * TODO: add case for J j = new C(); j.m() throws AME
       
   497      */
       
   498     public void testSuperDisqual() {
       
   499         Interface I = new Interface("I", DefaultMethod.std("99"));
       
   500         Interface J = new Interface("J", I, DefaultMethod.std("55"));
       
   501         Class C = new Class("C", I, J,
       
   502             new ConcreteMethod("int", stdMethodName, "return I.super.m();",
       
   503                 AccessFlag.PUBLIC));
       
   504         C.addCompilationDependency(I.findMethod(stdMethodName));
       
   505 
       
   506         assertThrows(AbstractMethodError.class, C);
       
   507     }
       
   508 
       
   509     /**
       
   510      * interface J { int m(); }
       
   511      * interface I extends J { default int m() { return J.super.m(); } }
       
   512      * class C implements I {}
       
   513      *
       
   514      * TEST: C c = new C(); c.m() throws AME
       
   515      * TODO: add case for I i = new C(); i.m() throws AME
       
   516      */
       
   517     public void testSuperNull() {
       
   518         Interface J = new Interface("J", AbstractMethod.std());
       
   519         Interface I = new Interface("I", J, new DefaultMethod(
       
   520             "int", stdMethodName, "return J.super.m();"));
       
   521         Interface Jstub = new Interface("J", DefaultMethod.std("99"));
       
   522         I.addCompilationDependency(Jstub);
       
   523         I.addCompilationDependency(Jstub.findMethod(stdMethodName));
       
   524         Class C = new Class("C", I);
       
   525 
       
   526         assertThrows(AbstractMethodError.class, C);
       
   527     }
       
   528 
       
   529     /**
       
   530      * interface J<T> { default int m(T t) { return 88; } }
       
   531      * interface I extends J<String> {
       
   532      *     int m(String s) default { return J.super.m(); }
       
   533      * }
       
   534      * class C implements I {}
       
   535      *
       
   536      * TEST: I i = new C(); i.m("") == 88;
       
   537      */
       
   538     public void testSuperGeneric() {
       
   539         Interface J = new Interface("J", new TypeParameter("T"),
       
   540             new DefaultMethod("int", stdMethodName, "return 88;",
       
   541                 new MethodParameter("T", "t")));
       
   542         Interface I = new Interface("I", J.with("String"),
       
   543             new DefaultMethod("int", stdMethodName, "return J.super.m(s);",
       
   544                 new MethodParameter("String", "s")));
       
   545         I.addCompilationDependency(J.findMethod(stdMethodName));
       
   546         Class C = new Class("C", I);
       
   547 
       
   548         AbstractMethod pm = new AbstractMethod("int", stdMethodName,
       
   549             new MethodParameter("String", "s"));
       
   550 
       
   551         assertInvokeInterfaceEquals(
       
   552             new Integer(88), C, new Extends(I), pm, "\"\"");
       
   553     }
       
   554 
       
   555     /**
       
   556      * interface I<T> { int m(T t) default { return 44; } }
       
   557      * interface J extends I<String> { int m(String s) default { return 55; } }
       
   558      * class C implements I<String>, J {
       
   559      *     public int m(String s) { return I.super.m(s); }
       
   560      * }
       
   561      *
       
   562      * TEST: C c = new C(); c.m("string") throws AME
       
   563      */
       
   564     public void testSuperGenericDisqual() {
       
   565         MethodParameter t = new MethodParameter("T", "t");
       
   566         MethodParameter s = new MethodParameter("String", "s");
       
   567 
       
   568         Interface I = new Interface("I", new TypeParameter("T"),
       
   569             new DefaultMethod("int", stdMethodName, "return 44;", t));
       
   570         Interface J = new Interface("J", I.with("String"),
       
   571             new DefaultMethod("int", stdMethodName, "return 55;", s));
       
   572         Class C = new Class("C", I.with("String"), J,
       
   573             new ConcreteMethod("int", stdMethodName,
       
   574                 "return I.super.m(s);", AccessFlag.PUBLIC, s));
       
   575         C.addCompilationDependency(I.findMethod(stdMethodName));
       
   576 
       
   577         assertThrows(AbstractMethodError.class, C,
       
   578             new ConcreteMethod(
       
   579                 "int", stdMethodName, "return -1;", AccessFlag.PUBLIC, s),
       
   580             "-1", "\"string\"");
       
   581     }
       
   582 
       
   583     /**
       
   584      * interface I { default Integer m() { return new Integer(88); } }
       
   585      * class C { int m() { return 99; } }
       
   586      * class D extends C implements I {}
       
   587      * class S { Object foo() { return (new D()).m(); } // link sig: ()LInteger;
       
   588      * TEST: S s = new S(); s.foo() == new Integer(88)
       
   589      */
       
   590     public void testNoCovarNoBridge() {
       
   591         Interface I = new Interface("I", new DefaultMethod(
       
   592             "Integer", "m", "return new Integer(88);"));
       
   593         Class C = new Class("C", new ConcreteMethod(
       
   594             "int", "m", "return 99;", AccessFlag.PUBLIC));
       
   595         Class D = new Class("D", I, C);
       
   596 
       
   597         ConcreteMethod DstubMethod = new ConcreteMethod(
       
   598             "Integer", "m", "return null;", AccessFlag.PUBLIC);
       
   599         Class Dstub = new Class("D", DstubMethod);
       
   600 
       
   601         ConcreteMethod toCall = new ConcreteMethod(
       
   602             "Object", "foo", "return (new D()).m();", AccessFlag.PUBLIC);
       
   603         Class S = new Class("S", D, toCall);
       
   604         S.addCompilationDependency(Dstub);
       
   605         S.addCompilationDependency(DstubMethod);
       
   606 
       
   607         assertInvokeVirtualEquals(new Integer(88), S, toCall, "null");
       
   608     }
       
   609 
       
   610     /**
       
   611      * interface J { int m(); }
       
   612      * interface I extends J { default int m() { return 99; } }
       
   613      * class B implements J {}
       
   614      * class C extends B implements I {}
       
   615      * TEST: C c = new C(); c.m() == 99
       
   616      *
       
   617      * The point of this test is that B does not get default method analysis,
       
   618      * and C does not generate any new miranda methods in the vtable.
       
   619      * It verifies that default method analysis occurs when mirandas have been
       
   620      * inherited and the supertypes don't have any overpass methods.
       
   621      */
       
   622     public void testNoNewMiranda() {
       
   623         Interface J = new Interface("J", AbstractMethod.std());
       
   624         Interface I = new Interface("I", J, DefaultMethod.std("99"));
       
   625         Class B = new Class("B", J);
       
   626         Class C = new Class("C", B, I);
       
   627         assertInvokeVirtualEquals(99, C);
       
   628     }
       
   629 
       
   630     public void testStrictfpDefault() {
       
   631         try {
       
   632             java.lang.Class.forName("vm.StrictfpDefault");
       
   633         } catch (Exception e) {
       
   634             fail("Could not load class", e);
       
   635         }
       
   636     }
       
   637 }