1 /*
   2  * Copyright (c) 2013, 2018, 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.runtime.defmeth;
  25 
  26 import nsk.share.test.TestBase;
  27 import vm.runtime.defmeth.shared.DefMethTest;
  28 import vm.runtime.defmeth.shared.annotation.Crash;
  29 import vm.runtime.defmeth.shared.annotation.KnownFailure;
  30 import vm.runtime.defmeth.shared.annotation.NotApplicableFor;
  31 import vm.runtime.defmeth.shared.data.*;
  32 import static vm.runtime.defmeth.shared.data.method.body.CallMethod.Invoke.*;
  33 import static vm.runtime.defmeth.shared.data.method.body.CallMethod.IndexbyteOp.*;
  34 import vm.runtime.defmeth.shared.builder.TestBuilder;
  35 import static vm.runtime.defmeth.shared.ExecutionMode.*;
  36 
  37 /**
  38  * Scenarios on private methods in interfaces.
  39  */
  40 public class PrivateMethodsTest extends DefMethTest {
  41 
  42     public static void main(String[] args) {
  43         TestBase.runTest(new PrivateMethodsTest(), args);
  44     }
  45 
  46     // invokevirtual & invokeinterface from same/subintf
  47     // Spec change July 2013 to not allow invokevirtual or invokeinterface
  48     // to even see an interface private method
  49     // Throw ICCE if method resolution returns interface private method
  50 
  51     /*
  52      * testPrivateInvokeVirtual
  53      *
  54      * interface I {
  55      *   default private int privateM() { return 1; }
  56      *   default public  int m()        { return (I)this.privateM(); } // invokevirtual
  57      * }
  58      * class C implements I {}
  59      *
  60      * TEST: I o = new C(); o.m()I throws VerifyError
  61      * TEST: C o = new C(); o.m()I throws VerifyError
  62      */
  63     @NotApplicableFor(modes = { REDEFINITION }) // Can't redefine a class that gets error during loading
  64     public void testPrivateInvokeVirtual() {
  65         TestBuilder b = factory.getBuilder();
  66 
  67         Interface I = b.intf("I")
  68                 .defaultMethod("privateM", "()I")
  69                     .private_().returns(1).build()
  70 
  71                 // force an invokevirtual of an IMR to test verification code
  72                 .defaultMethod("m", "()I")
  73                     .invoke(VIRTUAL, b.intfByName("I"), null, "privateM", "()I", INTERFACEMETHODREF).build()
  74             .build();
  75 
  76         ConcreteClass C = b.clazz("C").implement(I).build();
  77 
  78         b.test().callSite(I, C, "m", "()I").throws_(VerifyError.class).done()
  79          .test().callSite(C, C, "m", "()I").throws_(VerifyError.class).done()
  80 
  81         .run();
  82     }
  83 
  84     /*
  85      * testPrivateInvokeIntf
  86      *
  87      * interface I {
  88      *   default private int privateM() { return 1; }
  89      *   default public  int m()        { return (I)this.privateM(); } // invokeinterface
  90      * }
  91      * class C implements I {}
  92      *
  93      * TEST: I o = new C(); o.m()I throws IncompatibleClassChangeError
  94      * TEST: C o = new C(); o.m()I throws IncompatibleClassChangeError
  95      */
  96     public void testPrivateInvokeIntf() {
  97         TestBuilder b = factory.getBuilder();
  98 
  99         Interface I = b.intf("I")
 100                 .defaultMethod("privateM", "()I")
 101                     .private_().returns(1).build()
 102                 .defaultMethod("m", "()I")
 103                     .invoke(INTERFACE, b.intfByName("I"), null, "privateM", "()I", CALLSITE).build()
 104             .build();
 105 
 106         ConcreteClass C = b.clazz("C").implement(I).build();
 107 
 108         b.test().callSite(I, C, "m", "()I").throws_(IncompatibleClassChangeError.class).done()
 109          .test().callSite(C, C, "m", "()I").throws_(IncompatibleClassChangeError.class).done()
 110 
 111         .run();
 112     }
 113 
 114     /*
 115      * testPrivateInvokeStatic
 116      *
 117      * interface I {
 118      *   default private int privateM() { return 1; }
 119      *   default public  int m()        { return I.privateM(); } // invokestatic
 120      * }
 121      * class C implements I {}
 122      *
 123      * TEST: I o = new C(); o.m()I throws LinkageError
 124      * TEST: C o = new C(); o.m()I throws LinkageError
 125      */
 126     public void testPrivateInvokeStatic() {
 127         TestBuilder b = factory.getBuilder();
 128 
 129         Interface I = b.intf("I")
 130                 .defaultMethod("privateM", "()I")
 131                     .private_().returns(1).build()
 132                 .defaultMethod("m", "()I")
 133                     .invoke(STATIC, b.intfByName("I"), null, "privateM", "()I", CALLSITE).build()
 134             .build();
 135 
 136         ConcreteClass C = b.clazz("C").implement(I).build();
 137 
 138         b.test().callSite(I, C, "m", "()I").throws_(LinkageError.class).done()
 139          .test().callSite(C, C, "m", "()I").throws_(LinkageError.class).done()
 140 
 141         .run();
 142     }
 143 
 144     // call from another default method in the same interface
 145     /*
 146      * testPrivateCallSameClass
 147      *
 148      * interface I {
 149      *   default private privateM()I { return 1; }
 150      *   default public int m() { return I.super.privateM(); }
 151      * }
 152      * class C implements I {}
 153      *
 154      * TEST: { I o = new C(); o.m()I  == 1; }
 155      * TEST: { C o = new C(); o.m()I  == 1; }
 156      */
 157     public void testPrivateCallSameClass() {
 158         TestBuilder b = factory.getBuilder();
 159 
 160         Interface I = b.intf("I")
 161                 .defaultMethod("privateM", "()I")
 162                     .private_().returns(1).build()
 163                 .defaultMethod("m", "()I")
 164                     .invokeSpecial(b.intfByName("I"), "privateM", "()I").build()
 165             .build();
 166 
 167         ConcreteClass C = b.clazz("C").implement(I).build();
 168 
 169         b.test().callSite(I, C, "m", "()I").returns(1).done()
 170          .test().callSite(C, C, "m", "()I").returns(1).done()
 171 
 172         .run();
 173     }
 174 
 175     /*
 176      * testPrivateCallSubIntf
 177      *
 178      * Attempt to call from subinterface fails
 179 
 180      * interface I {
 181      *   default private privateM()I { return 1; }
 182      * }
 183      * J, K, L use invokespecial
 184      * interface J extends I {
 185      *   default public int m() { return I.super.privateM(); }
 186      * }
 187      * interface K extends I {
 188      *   default public int m() { return K.super.privateM(); }
 189      * }
 190      * interface L extends J {
 191      *   default public int m() { return I.super.privateM(); }
 192      * }
 193      * class C implements J {}
 194      * class D implements K {}
 195      * class E implements L {}
 196      *
 197      * TEST: { J o = new C(); o.m()I throws IAE; }
 198      * TEST: { C o = new C(); o.m()I throws IAE; }
 199      * TEST: { K o = new D(); o.m()I throws NSME; } // does not see
 200      * TEST: { D o = new D(); o.m()I throws NSME; }
 201      * TEST: { L o = new E(); o.m()I throws VerifyError; } // VerifyError intfmethodref
 202      * TEST: { E o = new E(); o.m()I throws VerifyError; }
 203      */
 204     @NotApplicableFor(modes = { REDEFINITION }) // Can't redefine a class that gets error during loading
 205     public void testPrivateCallSubIntf() {
 206         TestBuilder b = factory.getBuilder();
 207 
 208         Interface I = b.intf("I")
 209                 .defaultMethod("privateM", "()I")
 210                     .private_().returns(1).build()
 211             .build();
 212 
 213         Interface J = b.intf("J").extend(I)
 214                 .defaultMethod("m", "()I")
 215                     .invokeSpecial(I, "privateM", "()I").build()
 216             .build();
 217 
 218         Interface K = b.intf("K").extend(J)
 219                 .defaultMethod("m", "()I")
 220                     .invokeSpecial(b.intfByName("K"), "privateM", "()I").build()
 221             .build();
 222 
 223         // L.privateM -> J -> L (I.privateM call)
 224         Interface L = b.intf("L").extend(J)
 225                 .defaultMethod("m", "()I")
 226                     .invokeSpecial(I, "privateM", "()I").build()
 227             .build();
 228 
 229         ConcreteClass C = b.clazz("C").implement(J).build();
 230 
 231         ConcreteClass D = b.clazz("D").implement(K).build();
 232 
 233         ConcreteClass E = b.clazz("E").implement(L).build();
 234 
 235         b.test().callSite(J, C, "m", "()I").throws_(IllegalAccessError.class).done()
 236          .test().callSite(C, C, "m", "()I").throws_(IllegalAccessError.class).done()
 237 
 238          .test().callSite(K, D, "m", "()I").throws_(NoSuchMethodError.class).done()
 239          .test().callSite(D, D, "m", "()I").throws_(NoSuchMethodError.class).done()
 240 
 241          .test().callSite(L, E, "m", "()I").throws_(VerifyError.class).done()
 242          .test().callSite(E, E, "m", "()I").throws_(VerifyError.class).done()
 243 
 244         .run();
 245     }
 246 
 247     /*
 248      * Attempt to call from subclass fails
 249      *
 250      * interface I {
 251      *   default private privateM()I { return 1; }
 252      * }
 253      * class C implements I {
 254      *   public int m() { return I.super.privateM(); }
 255      * }
 256      * class D extends C {
 257      *   public int m() { return I.super.privateM(); }
 258      * }
 259      * class E extends C {
 260      *   public int m() { return C.super.privateM(); }
 261      * }
 262      *
 263      * TEST: { C o = new C(); o.m()I throws LinkageError }
 264      * TEST: { D o = new D(); o.m()I throws LinkageError }
 265      * TEST: { E o = new E(); o.m()I throws NoSuchMethodError; }
 266      */
 267     @NotApplicableFor(modes = { REDEFINITION }) // Can't redefine a class that gets error during loading
 268     public void testPrivateCallImplClass() {
 269         TestBuilder b = factory.getBuilder();
 270 
 271         Interface I = b.intf("I")
 272                 .defaultMethod("privateM", "()I")
 273                     .private_().returns(1).build()
 274             .build();
 275 
 276         ConcreteClass C = b.clazz("C").implement(I)
 277                 .concreteMethod("m", "()I")
 278                     .invokeSpecial(I, "privateM", "()I").build()
 279             .build();
 280 
 281         ConcreteClass D = b.clazz("D").extend(C)
 282                 .concreteMethod("m", "()I")
 283                     .invokeSpecial(I, "privateM", "()I").build()
 284             .build();
 285 
 286         ConcreteClass E = b.clazz("E").extend(C)
 287                 .concreteMethod("m", "()I")
 288                     .invokeSpecial(C, "privateM", "()I").build()
 289             .build();
 290 
 291         Class eeExpectedClass;
 292         if (factory.getVer() >= 52) {
 293             eeExpectedClass = NoSuchMethodError.class;
 294         } else {
 295             // The test gets a VerifyError in this case due to an
 296             // invokespecial IMR bytecode.  This was not allowed
 297             // until class file version 52.  (See 8030249.)
 298             eeExpectedClass = VerifyError.class;
 299         }
 300         b.test().callSite(C, C, "m", "()I").throws_(LinkageError.class).done()
 301          .test().callSite(D, D, "m", "()I").throws_(LinkageError.class).done()
 302          .test().callSite(E, E, "m", "()I").throws_(eeExpectedClass).done()
 303 
 304         .run();
 305     }
 306 
 307     // doesn't participate in default method analysis
 308     //   method overriding
 309 
 310     /*
 311      * testPrivateDefault
 312      *
 313      * interface I {
 314      *   default private int m() { return 1; }
 315      * }
 316      * class C implements I {}
 317      *
 318      * TEST: { I o = new C(); o.m()I throws IllegalAccessError; }
 319      *                 -mode reflect throws NoSuchMethodException
 320      * TEST: { C o = new C(); o.m()I throws java/lang/NoSuchMethodError; }
 321      */
 322     public void testPrivateDefault() {
 323         TestBuilder b = factory.getBuilder();
 324 
 325         Interface I = b.intf("I")
 326                 .defaultMethod("m", "()I")
 327                     .private_().returns(1).build()
 328             .build();
 329 
 330         ConcreteClass C = b.clazz("C").implement(I).build();
 331 
 332         Class expectedClass;
 333         if (factory.getExecutionMode().equals("REFLECTION")) {
 334             expectedClass = NoSuchMethodException.class;
 335         } else {
 336             expectedClass = IllegalAccessError.class;
 337         }
 338 
 339         b.test().callSite(I, C, "m", "()I").throws_(expectedClass).done()
 340          .test().callSite(C, C, "m", "()I").throws_(NoSuchMethodError.class).done()
 341 
 342         .run();
 343     }
 344 
 345     /*
 346      * testPrivateDefaultVsConcrete
 347      *
 348      * interface I {
 349      *   default private int m() { return 1; }
 350      * }
 351      * class C implements I {
 352      *   public int m() { return 2; }
 353      * }
 354      *
 355      * TEST: { I o = new C(); o.m()I  == IllegalAccessError; }
 356      *                 -mode reflect throws NoSuchMethodException
 357      * TEST: { C o = new C(); o.m()I  == 2; }
 358      */
 359     public void testPrivateDefaultVsConcrete() {
 360         TestBuilder b = factory.getBuilder();
 361 
 362         Interface I = b.intf("I")
 363                 .defaultMethod("m", "()I")
 364                     .private_().returns(1).build()
 365             .build();
 366 
 367         ConcreteClass C = b.clazz("C").implement(I)
 368                 .concreteMethod("m", "()I").returns(2).build()
 369             .build();
 370 
 371         Class expectedClass;
 372         if (factory.getExecutionMode().equals("REFLECTION")) {
 373             expectedClass = NoSuchMethodException.class;
 374         } else {
 375             expectedClass = IllegalAccessError.class;
 376         }
 377 
 378         b.test().callSite(I, C, "m", "()I").throws_(expectedClass).done()
 379          .test().callSite(C, C, "m", "()I").returns(2).done()
 380 
 381         .run();
 382     }
 383 
 384     /*
 385      * testPublicOverridePrivate
 386      *
 387      * interface I {
 388      *   default private int m() { return 1; }
 389      * }
 390      * interface J extends I {
 391      *   default public int m() { return 2; }
 392      * }
 393      * class C implements J {}
 394      *
 395      * TEST: { I o = new C(); o.m()I throws IllegalAccessError; }
 396      *                 -mode reflect throws NoSuchMethodException
 397      * TEST: { J o = new C(); o.m()I  == 2; }
 398      * TEST: { C o = new C(); o.m()I  == 2; }
 399      */
 400     public void testPublicOverridePrivate() {
 401         TestBuilder b = factory.getBuilder();
 402 
 403         Interface I = b.intf("I")
 404                 .defaultMethod("m", "()I")
 405                     .private_().returns(1).build()
 406             .build();
 407 
 408         Interface J = b.intf("J").extend(I)
 409                 .defaultMethod("m", "()I")
 410                     .returns(2).build()
 411             .build();
 412 
 413         ConcreteClass C = b.clazz("C").implement(J).build();
 414 
 415         Class expectedClass;
 416         if (factory.getExecutionMode().equals("REFLECTION")) {
 417             expectedClass = NoSuchMethodException.class;
 418         } else {
 419             expectedClass = IllegalAccessError.class;
 420         }
 421 
 422         b.test().callSite(I, C, "m", "()I").throws_(expectedClass).done()
 423          .test().callSite(J, C, "m", "()I").returns(2).done()
 424          .test().callSite(C, C, "m", "()I").returns(2).done()
 425 
 426         .run();
 427     }
 428 
 429     /*
 430      * testPrivateOverrideDefault
 431      *
 432      * interface I {
 433      *   default public int m() { return 1; }
 434      * }
 435      * interface J extends I {
 436      *   default private int m() { return 2; }
 437      * }
 438      * class C implements J {}
 439      *
 440      * TEST: { I o = new C(); o.m()I  == 1; }
 441      * TEST: { J o = new C(); o.m()I  == IllegalAccessError; } II J.m priv
 442      * TEST: { C o = new C(); o.m()I  == 1; }
 443      */
 444     /*
 445 
 446         REFLECTION:
 447   Test2_J_C_m                   : FAILED
 448     nsk.share.TestFailure: Caught exception as expected, but its type is wrong:
 449       expected: java.lang.IllegalAccessError;
 450       actual: java.lang.NoSuchMethodException.
 451      */
 452     public void testPrivateOverrideDefault() {
 453         TestBuilder b = factory.getBuilder();
 454 
 455         Interface I = b.intf("I")
 456                 .defaultMethod("m", "()I")
 457                     .returns(1).build()
 458             .build();
 459 
 460         Interface J = b.intf("J").extend(I)
 461                 .defaultMethod("m", "()I")
 462                     .private_().returns(2).build()
 463             .build();
 464 
 465         ConcreteClass C = b.clazz("C").implement(J).build();
 466 
 467         b.test().callSite(I, C, "m", "()I").returns(1).done()
 468          .test().privateCallSite(J, C, "m", "()I").throws_(IllegalAccessError.class).done()
 469          .test().callSite(C, C, "m", "()I").returns(1).done()
 470 
 471         .run();
 472     }
 473 
 474     /*
 475      * testPrivateReabstract
 476      *
 477      * interface I {
 478      *   default private int m() { return 1; }
 479      * }
 480      * interface J extends I {
 481      *   abstract public int m();
 482      * }
 483      * class C implements J {}
 484      *
 485      * TEST: { I o = new C(); o.m()I throws IllegalAccessError; } II I.m
 486      *                 -mode reflect throws NoSuchMethodException
 487      * TEST: { J o = new C(); o.m()I throws java/lang/AbstractMethodError; }
 488      * TEST: { C o = new C(); o.m()I throws java/lang/AbstractMethodError; }
 489      */
 490     public void testPrivateReabstract() {
 491         TestBuilder b = factory.getBuilder();
 492 
 493         Interface I = b.intf("I")
 494                 .defaultMethod("m", "()I")
 495                     .private_().returns(1).build()
 496             .build();
 497 
 498         Interface J = b.intf("J").extend(I)
 499                 .abstractMethod("m", "()I").build()
 500             .build();
 501 
 502         ConcreteClass C = b.clazz("C").implement(J).build();
 503 
 504         Class expectedClass;
 505         if (factory.getExecutionMode().equals("REFLECTION")) {
 506             expectedClass = NoSuchMethodException.class;
 507         } else {
 508             expectedClass = IllegalAccessError.class;
 509         }
 510 
 511         b.test().callSite(I, C, "m", "()I").throws_(expectedClass).done()
 512          .test().callSite(J, C, "m", "()I").throws_(AbstractMethodError.class).done()
 513          .test().callSite(C, C, "m", "()I").throws_(AbstractMethodError.class).done()
 514 
 515         .run();
 516     }
 517 
 518     /*
 519      * testPrivateOverrideAbstract
 520      *
 521      * interface I {
 522      *   abstract public int m();
 523      * }
 524      * interface J extends I {
 525      *   default private int m() { return 1; }
 526      * }
 527      * class C implements J {}
 528      *
 529      * TEST: { I o = new C(); o.m()I throws AbstractMethodError }
 530      * TEST: { J o = new C(); o.m()I throws IncompatibleClassChangeError }
 531      * TEST: { C o = new C(); o.m()I throws AbstractMethodError }
 532      */
 533     /*
 534          REFLECTION:
 535   Test1_I_C_m                   : FAILED
 536     nsk.share.TestFailure: No exception was thrown: java.lang.AbstractMethodError
 537   Test2_J_C_m                   : FAILED
 538     nsk.share.TestFailure: No exception was thrown: java.lang.AbstractMethodError
 539   Test3_C_C_m                   : FAILED
 540     nsk.share.TestFailure: No exception was thrown: java.lang.AbstractMethodError
 541      */
 542     public void testPrivateOverrideAbstract() {
 543         TestBuilder b = factory.getBuilder();
 544 
 545         Interface I = b.intf("I")
 546                 .abstractMethod("m", "()I").build()
 547             .build();
 548 
 549         Interface J = b.intf("J").extend(I)
 550                 .defaultMethod("m", "()I")
 551                     .private_().returns(1).build()
 552             .build();
 553 
 554         ConcreteClass C = b.clazz("C").implement(J).build();
 555 
 556         Class expectedClass;
 557         if (factory.getExecutionMode().equals("REFLECTION")) {
 558             expectedClass = IllegalAccessException.class;
 559         } else {
 560             expectedClass = IncompatibleClassChangeError.class;
 561         }
 562 
 563         b.test().callSite(I, C, "m", "()I").throws_(AbstractMethodError.class).done()
 564          .test().privateCallSite(J, C, "m", "()I").throws_(expectedClass).done()
 565          .test().callSite(C, C, "m", "()I").throws_(AbstractMethodError.class).done()
 566          .run();
 567     }
 568 
 569     /*
 570      * testPrivateInheritedDefault
 571      *
 572      * interface I {
 573      *   default private int m() { return 1; }
 574      * }
 575      * class B implements I {}
 576      * class C extends B {}
 577      *
 578      * TEST: { I o = new C(); o.m()I throws IllegalAccessError } II I.m
 579      *                 -mode reflect throws NoSuchMethodException
 580      * TEST: { B o = new C(); o.m()I throws NoSuchMethodError }
 581      * TEST: { C o = new C(); o.m()I throws NoSuchMethodError }
 582      */
 583     public void testPrivateInheritedDefault() {
 584         TestBuilder b = factory.getBuilder();
 585 
 586         Interface I = b.intf("I")
 587                 .defaultMethod("m", "()I")
 588                     .private_().returns(1).build()
 589             .build();
 590 
 591         ConcreteClass B = b.clazz("B").implement(I).build();
 592         ConcreteClass C = b.clazz("C").extend(B).build();
 593 
 594         Class expectedClass;
 595         if (factory.getExecutionMode().equals("REFLECTION")) {
 596             expectedClass = NoSuchMethodException.class;
 597         } else {
 598             expectedClass = IllegalAccessError.class;
 599         }
 600 
 601         b.test().callSite(I, C, "m","()I").throws_(expectedClass).done()
 602          .test().callSite(B, C, "m","()I").throws_(NoSuchMethodError.class).done()
 603          .test().callSite(C, C, "m","()I").throws_(NoSuchMethodError.class).done()
 604 
 605         .run();
 606 
 607     }
 608 
 609     /*
 610      * testPrivateDefaultVsConcreteInherited
 611      *
 612      * interface I {
 613      *    default private int m() { return 1; }
 614      * }
 615      * class B {
 616      *   public int m() { return 2; }
 617      * }
 618      * class C extends B implements I {}
 619      *
 620      * TEST: { I o = new C(); o.m()I  == throws IllegalAccessError; }
 621      *                     -mode reflect throws NoSuchMethodException
 622      * TEST: { B o = new C(); o.m()I  == 2; }
 623      * TEST: { C o = new C(); o.m()I  == 2; }
 624      */
 625     public void testPrivateDefaultVsConcreteInherited() {
 626         TestBuilder b = factory.getBuilder();
 627 
 628         Interface I = b.intf("I")
 629                 .defaultMethod("m", "()I")
 630                     .private_().returns(1).build()
 631             .build();
 632 
 633         ConcreteClass B = b.clazz("B")
 634                 .concreteMethod("m", "()I").returns(2).build()
 635                 .build();
 636 
 637         ConcreteClass C = b.clazz("C").extend(B).implement(I).build();
 638 
 639         Class expectedClass;
 640         if (factory.getExecutionMode().equals("REFLECTION")) {
 641             expectedClass = NoSuchMethodException.class;
 642         } else {
 643             expectedClass = IllegalAccessError.class;
 644         }
 645 
 646         b.test().callSite(I, C, "m","()I").throws_(expectedClass).done()
 647          .test().callSite(B, C, "m","()I").returns(2).done()
 648          .test().callSite(C, C, "m","()I").returns(2).done()
 649 
 650         .run();
 651     }
 652 
 653     /*
 654      * testPrivateConflict
 655      *
 656      * Conflicting default methods
 657      *
 658      * interface I {
 659      *   default private int m() { return 1; }
 660      * }
 661      * interface J {
 662      *   default public int m() { return 2; }
 663      * }
 664      * class C implements I, J {}
 665      *
 666      * TEST: { I o = new C(); o.m()I throws IllegalAccessError; }
 667      *                 -mode reflect throws NoSuchMethodException
 668      * TEST: { J o = new C(); o.m()I  == 2; }
 669      * TEST: { C o = new C(); o.m()I  == 2; }
 670      */
 671     public void testPrivateConflict() {
 672         TestBuilder b = factory.getBuilder();
 673 
 674         Interface I = b.intf("I")
 675                 .defaultMethod("m", "()I").private_().returns(1).build()
 676             .build();
 677 
 678         Interface J = b.intf("J")
 679                 .defaultMethod("m", "()I").returns(2).build()
 680             .build();
 681 
 682         ConcreteClass C = b.clazz("C").implement(I,J).build();
 683 
 684         Class expectedClass;
 685         if (factory.getExecutionMode().equals("REFLECTION")) {
 686             expectedClass = NoSuchMethodException.class;
 687         } else {
 688             expectedClass = IllegalAccessError.class;
 689         }
 690 
 691         b.test().callSite(I, C, "m", "()I").throws_(expectedClass).done()
 692          .test().callSite(J, C, "m", "()I").returns(2).done()
 693          .test().callSite(C, C, "m", "()I").returns(2).done()
 694 
 695         .run();
 696     }
 697     /*
 698      * testPrivateSuperClassMethodNoDefaultMethod
 699      *
 700      * interface I {
 701      *  public int m();
 702      * }
 703      *
 704      * public class A {
 705      *  private int m() { return 1; }
 706      * }
 707      *
 708      * public class B extends A implements I {}
 709      *
 710      * public class C extends B {
 711      *  public int m() { return 2; }
 712      * }
 713      *
 714      * TEST: { B b = new C(); b.m()I throws IllegalAccessError; }
 715      */
 716     public void testPrivateSuperClassMethodNoDefaultMethod() {
 717         TestBuilder b = factory.getBuilder();
 718 
 719         ConcreteClass A = b.clazz("A")
 720                 .concreteMethod("m", "()I").private_().returns(1).build()
 721                 .build();
 722 
 723         Interface I = b.intf("I")
 724                 .abstractMethod("m", "()I").public_().build()
 725                 .build();
 726 
 727         ConcreteClass B = b.clazz("B").extend(A).implement(I).build();
 728 
 729         ConcreteClass C = b.clazz("C").extend(B)
 730                 .concreteMethod("m", "()I").public_().returns(2).build()
 731                 .build();
 732 
 733         b.test().privateCallSite(B, C, "m", "()I").throws_(IllegalAccessError.class).done()
 734         .run();
 735 
 736     }
 737 
 738     /*
 739      * testPrivateSuperClassMethodDefaultMethod
 740      *
 741      * interface I {
 742      *  public default int m() { return 3; }
 743      * }
 744      *
 745      * public class A {
 746      *  private int m() { return 1; }
 747      * }
 748      *
 749      * public class B extends A implements I {}
 750      *
 751      * public class C extends B {
 752      *  public int m() { return 2; }
 753      * }
 754      *
 755      * TEST: { B b = new C(); b.m()I throws IllegalAccessError; }
 756      */
 757     public void testPrivateSuperClassMethodDefaultMethod() {
 758         TestBuilder b = factory.getBuilder();
 759 
 760         ConcreteClass A = b.clazz("A")
 761                 .concreteMethod("m", "()I").private_().returns(1).build()
 762                 .build();
 763 
 764         Interface I = b.intf("I")
 765                 .defaultMethod("m", "()I").public_().returns(3).build()
 766                 .build();
 767 
 768         ConcreteClass B = b.clazz("B").extend(A).implement(I).build();
 769 
 770         ConcreteClass C = b.clazz("C").extend(B)
 771                 .concreteMethod("m", "()I").public_().returns(2).build()
 772                 .build();
 773 
 774         b.test().privateCallSite(B, C, "m", "()I").throws_(IllegalAccessError.class).done()
 775         .run();
 776     }
 777 
 778     /*
 779      * testPrivateSuperClassMethodDefaultMethodNoOverride
 780      *
 781      * interface I {
 782      *  public default int m() { return 3; }
 783      * }
 784      *
 785      * public class A {
 786      *  private int m() { return 1; }
 787      * }
 788      *
 789      * public class B extends A implements I {}
 790      *
 791      * public class C extends B { }
 792      *
 793      * TEST: { B b = new C(); b.m()I throws IllegalAccessError; }
 794      */
 795     public void testPrivateSuperClassMethodDefaultMethodNoOverride() {
 796         TestBuilder b = factory.getBuilder();
 797 
 798         ConcreteClass A = b.clazz("A")
 799                 .concreteMethod("m", "()I").private_().returns(1).build()
 800                 .build();
 801 
 802         Interface I = b.intf("I")
 803                 .defaultMethod("m", "()I").public_().returns(3).build()
 804                 .build();
 805 
 806         ConcreteClass B = b.clazz("B").extend(A).implement(I).build();
 807 
 808         ConcreteClass C = b.clazz("C").extend(B).build();
 809 
 810         b.test().privateCallSite(B, C, "m", "()I").throws_(IllegalAccessError.class).done()
 811         .run();
 812     }
 813 
 814 }