< prev index next >

test/hotspot/jtreg/vmTestbase/vm/runtime/defmeth/PrivateMethodsTest.java

Print this page
rev 50606 : imported patch jep181-rev3

*** 46,60 **** // invokevirtual & invokeinterface from same/subintf // Spec change July 2013 to not allow invokevirtual or invokeinterface // to even see an interface private method // Throw ICCE if method resolution returns interface private method /* * testPrivateInvokeVirtual * * interface I { ! * default private int privateM() { return 1; } * default public int m() { return (I)this.privateM(); } // invokevirtual * } * class C implements I {} * * TEST: I o = new C(); o.m()I throws VerifyError --- 46,77 ---- // invokevirtual & invokeinterface from same/subintf // Spec change July 2013 to not allow invokevirtual or invokeinterface // to even see an interface private method // Throw ICCE if method resolution returns interface private method + // Spec change JDK 11 - invokeinterface can be used for private interface + // methods and is now the preferred invocation bytecode - so no ICCE. + // Private methods are skipped during selection unless the resolved method + // is private. + // This change is not dependent on the classfile version. + + // Note on reflection testing: + // Reflection is only used for the initial callsite, which is not always + // the method of interest. For example where a default method m() calls + // the private interface method privateM(). It is the latter call we are + // really testing, but it is the call of the default method that occurs + // via reflection. + // In private cases reflection triggers a NoSuchMethodException instead of the + // expected IllegalAccessError. This indicates it is getDeclaredMethod() that is + // failing rather than the actual invoke(). Which in turn suggests the wrong class + // is being used, or that getMethod() is being used instead of getDeclaredMethod(). + /* * testPrivateInvokeVirtual * * interface I { ! * private int privateM() { return 1; } * default public int m() { return (I)this.privateM(); } // invokevirtual * } * class C implements I {} * * TEST: I o = new C(); o.m()I throws VerifyError
*** 83,99 **** /* * testPrivateInvokeIntf * * interface I { ! * default private int privateM() { return 1; } * default public int m() { return (I)this.privateM(); } // invokeinterface * } * class C implements I {} * ! * TEST: I o = new C(); o.m()I throws IncompatibleClassChangeError ! * TEST: C o = new C(); o.m()I throws IncompatibleClassChangeError */ public void testPrivateInvokeIntf() { TestBuilder b = factory.getBuilder(); Interface I = b.intf("I") --- 100,116 ---- /* * testPrivateInvokeIntf * * interface I { ! * private int privateM() { return 1; } * default public int m() { return (I)this.privateM(); } // invokeinterface * } * class C implements I {} * ! * TEST: I o = new C(); o.m()I returns 1 ! * TEST: C o = new C(); o.m()I returns 1 */ public void testPrivateInvokeIntf() { TestBuilder b = factory.getBuilder(); Interface I = b.intf("I")
*** 103,129 **** .invoke(INTERFACE, b.intfByName("I"), null, "privateM", "()I", CALLSITE).build() .build(); ConcreteClass C = b.clazz("C").implement(I).build(); ! b.test().callSite(I, C, "m", "()I").throws_(IncompatibleClassChangeError.class).done() ! .test().callSite(C, C, "m", "()I").throws_(IncompatibleClassChangeError.class).done() .run(); } /* * testPrivateInvokeStatic * * interface I { ! * default private int privateM() { return 1; } * default public int m() { return I.privateM(); } // invokestatic * } * class C implements I {} * ! * TEST: I o = new C(); o.m()I throws LinkageError ! * TEST: C o = new C(); o.m()I throws LinkageError */ public void testPrivateInvokeStatic() { TestBuilder b = factory.getBuilder(); Interface I = b.intf("I") --- 120,146 ---- .invoke(INTERFACE, b.intfByName("I"), null, "privateM", "()I", CALLSITE).build() .build(); ConcreteClass C = b.clazz("C").implement(I).build(); ! b.test().callSite(I, C, "m", "()I").returns(1).done() ! .test().callSite(C, C, "m", "()I").returns(1).done() .run(); } /* * testPrivateInvokeStatic * * interface I { ! * private int privateM() { return 1; } * default public int m() { return I.privateM(); } // invokestatic * } * class C implements I {} * ! * TEST: I o = new C(); o.m()I throws IncompatibleClassChangeError ! * TEST: C o = new C(); o.m()I throws IncompatibleClassChangeError */ public void testPrivateInvokeStatic() { TestBuilder b = factory.getBuilder(); Interface I = b.intf("I")
*** 133,155 **** .invoke(STATIC, b.intfByName("I"), null, "privateM", "()I", CALLSITE).build() .build(); ConcreteClass C = b.clazz("C").implement(I).build(); ! b.test().callSite(I, C, "m", "()I").throws_(LinkageError.class).done() ! .test().callSite(C, C, "m", "()I").throws_(LinkageError.class).done() .run(); } // call from another default method in the same interface /* * testPrivateCallSameClass * * interface I { ! * default private privateM()I { return 1; } ! * default public int m() { return I.super.privateM(); } * } * class C implements I {} * * TEST: { I o = new C(); o.m()I == 1; } * TEST: { C o = new C(); o.m()I == 1; } --- 150,172 ---- .invoke(STATIC, b.intfByName("I"), null, "privateM", "()I", CALLSITE).build() .build(); ConcreteClass C = b.clazz("C").implement(I).build(); ! b.test().callSite(I, C, "m", "()I").throws_(IncompatibleClassChangeError.class).done() ! .test().callSite(C, C, "m", "()I").throws_(IncompatibleClassChangeError.class).done() .run(); } // call from another default method in the same interface /* * testPrivateCallSameClass * * interface I { ! * private privateM()I { return 1; } ! * default public int m() { return I.super.privateM(); } // invokespecial * } * class C implements I {} * * TEST: { I o = new C(); o.m()I == 1; } * TEST: { C o = new C(); o.m()I == 1; }
*** 176,186 **** * testPrivateCallSubIntf * * Attempt to call from subinterface fails * interface I { ! * default private privateM()I { return 1; } * } * J, K, L use invokespecial * interface J extends I { * default public int m() { return I.super.privateM(); } * } --- 193,203 ---- * testPrivateCallSubIntf * * Attempt to call from subinterface fails * interface I { ! * private privateM()I { return 1; } * } * J, K, L use invokespecial * interface J extends I { * default public int m() { return I.super.privateM(); } * }
*** 246,256 **** /* * Attempt to call from subclass fails * * interface I { ! * default private privateM()I { return 1; } * } * class C implements I { * public int m() { return I.super.privateM(); } * } * class D extends C { --- 263,273 ---- /* * Attempt to call from subclass fails * * interface I { ! * private privateM()I { return 1; } * } * class C implements I { * public int m() { return I.super.privateM(); } * } * class D extends C {
*** 258,270 **** * } * class E extends C { * public int m() { return C.super.privateM(); } * } * ! * TEST: { C o = new C(); o.m()I throws LinkageError } ! * TEST: { D o = new D(); o.m()I throws LinkageError } ! * TEST: { E o = new E(); o.m()I throws NoSuchMethodError; } */ @NotApplicableFor(modes = { REDEFINITION }) // Can't redefine a class that gets error during loading public void testPrivateCallImplClass() { TestBuilder b = factory.getBuilder(); --- 275,287 ---- * } * class E extends C { * public int m() { return C.super.privateM(); } * } * ! * TEST: { C o = new C(); o.m()I throws IllegalAccessError (or VerifyError) } ! * TEST: { D o = new D(); o.m()I throws VerifyError } ! * TEST: { E o = new E(); o.m()I throws NoSuchMethodError (or VerifyError); } */ @NotApplicableFor(modes = { REDEFINITION }) // Can't redefine a class that gets error during loading public void testPrivateCallImplClass() { TestBuilder b = factory.getBuilder();
*** 287,327 **** .concreteMethod("m", "()I") .invokeSpecial(C, "privateM", "()I").build() .build(); Class eeExpectedClass; if (factory.getVer() >= 52) { eeExpectedClass = NoSuchMethodError.class; } else { // The test gets a VerifyError in this case due to an // invokespecial IMR bytecode. This was not allowed // until class file version 52. (See 8030249.) eeExpectedClass = VerifyError.class; } ! b.test().callSite(C, C, "m", "()I").throws_(LinkageError.class).done() ! .test().callSite(D, D, "m", "()I").throws_(LinkageError.class).done() .test().callSite(E, E, "m", "()I").throws_(eeExpectedClass).done() .run(); } // doesn't participate in default method analysis // method overriding /* ! * testPrivateDefault * * interface I { ! * default private int m() { return 1; } * } * class C implements I {} * * TEST: { I o = new C(); o.m()I throws IllegalAccessError; } * -mode reflect throws NoSuchMethodException ! * TEST: { C o = new C(); o.m()I throws java/lang/NoSuchMethodError; } */ ! public void testPrivateDefault() { TestBuilder b = factory.getBuilder(); Interface I = b.intf("I") .defaultMethod("m", "()I") .private_().returns(1).build() --- 304,347 ---- .concreteMethod("m", "()I") .invokeSpecial(C, "privateM", "()I").build() .build(); Class eeExpectedClass; + Class ccExpectedClass; if (factory.getVer() >= 52) { eeExpectedClass = NoSuchMethodError.class; + ccExpectedClass = IllegalAccessError.class; } else { // The test gets a VerifyError in this case due to an // invokespecial IMR bytecode. This was not allowed // until class file version 52. (See 8030249.) eeExpectedClass = VerifyError.class; + ccExpectedClass = VerifyError.class; } ! b.test().callSite(C, C, "m", "()I").throws_(ccExpectedClass).done() ! .test().callSite(D, D, "m", "()I").throws_(VerifyError.class).done() .test().callSite(E, E, "m", "()I").throws_(eeExpectedClass).done() .run(); } // doesn't participate in default method analysis // method overriding /* ! * testPrivate * * interface I { ! * private int m() { return 1; } * } * class C implements I {} * * TEST: { I o = new C(); o.m()I throws IllegalAccessError; } * -mode reflect throws NoSuchMethodException ! * TEST: { C o = new C(); o.m()I throws NoSuchMethodError; } */ ! public void testPrivate() { TestBuilder b = factory.getBuilder(); Interface I = b.intf("I") .defaultMethod("m", "()I") .private_().returns(1).build()
*** 341,364 **** .run(); } /* ! * testPrivateDefaultVsConcrete * * interface I { ! * default private int m() { return 1; } * } * class C implements I { * public int m() { return 2; } * } * * TEST: { I o = new C(); o.m()I == IllegalAccessError; } * -mode reflect throws NoSuchMethodException * TEST: { C o = new C(); o.m()I == 2; } */ ! public void testPrivateDefaultVsConcrete() { TestBuilder b = factory.getBuilder(); Interface I = b.intf("I") .defaultMethod("m", "()I") .private_().returns(1).build() --- 361,384 ---- .run(); } /* ! * testPrivateVsConcrete * * interface I { ! * private int m() { return 1; } * } * class C implements I { * public int m() { return 2; } * } * * TEST: { I o = new C(); o.m()I == IllegalAccessError; } * -mode reflect throws NoSuchMethodException * TEST: { C o = new C(); o.m()I == 2; } */ ! public void testPrivateVsConcrete() { TestBuilder b = factory.getBuilder(); Interface I = b.intf("I") .defaultMethod("m", "()I") .private_().returns(1).build()
*** 383,393 **** /* * testPublicOverridePrivate * * interface I { ! * default private int m() { return 1; } * } * interface J extends I { * default public int m() { return 2; } * } * class C implements J {} --- 403,413 ---- /* * testPublicOverridePrivate * * interface I { ! * private int m() { return 1; } * } * interface J extends I { * default public int m() { return 2; } * } * class C implements J {}
*** 431,456 **** * * interface I { * default public int m() { return 1; } * } * interface J extends I { ! * default private int m() { return 2; } * } * class C implements J {} * * TEST: { I o = new C(); o.m()I == 1; } * TEST: { J o = new C(); o.m()I == IllegalAccessError; } II J.m priv * TEST: { C o = new C(); o.m()I == 1; } */ - /* - - REFLECTION: - Test2_J_C_m : FAILED - nsk.share.TestFailure: Caught exception as expected, but its type is wrong: - expected: java.lang.IllegalAccessError; - actual: java.lang.NoSuchMethodException. - */ public void testPrivateOverrideDefault() { TestBuilder b = factory.getBuilder(); Interface I = b.intf("I") .defaultMethod("m", "()I") --- 451,468 ---- * * interface I { * default public int m() { return 1; } * } * interface J extends I { ! * private int m() { return 2; } * } * class C implements J {} * * TEST: { I o = new C(); o.m()I == 1; } * TEST: { J o = new C(); o.m()I == IllegalAccessError; } II J.m priv * TEST: { C o = new C(); o.m()I == 1; } */ public void testPrivateOverrideDefault() { TestBuilder b = factory.getBuilder(); Interface I = b.intf("I") .defaultMethod("m", "()I")
*** 473,483 **** /* * testPrivateReabstract * * interface I { ! * default private int m() { return 1; } * } * interface J extends I { * abstract public int m(); * } * class C implements J {} --- 485,495 ---- /* * testPrivateReabstract * * interface I { ! * private int m() { return 1; } * } * interface J extends I { * abstract public int m(); * } * class C implements J {}
*** 520,546 **** * * interface I { * abstract public int m(); * } * interface J extends I { ! * default private int m() { return 1; } * } * class C implements J {} * * TEST: { I o = new C(); o.m()I throws AbstractMethodError } ! * TEST: { J o = new C(); o.m()I throws IncompatibleClassChangeError } * TEST: { C o = new C(); o.m()I throws AbstractMethodError } */ - /* - REFLECTION: - Test1_I_C_m : FAILED - nsk.share.TestFailure: No exception was thrown: java.lang.AbstractMethodError - Test2_J_C_m : FAILED - nsk.share.TestFailure: No exception was thrown: java.lang.AbstractMethodError - Test3_C_C_m : FAILED - nsk.share.TestFailure: No exception was thrown: java.lang.AbstractMethodError - */ public void testPrivateOverrideAbstract() { TestBuilder b = factory.getBuilder(); Interface I = b.intf("I") .abstractMethod("m", "()I").build() --- 532,549 ---- * * interface I { * abstract public int m(); * } * interface J extends I { ! * private int m() { return 1; } * } * class C implements J {} * * TEST: { I o = new C(); o.m()I throws AbstractMethodError } ! * TEST: { J o = new C(); o.m()I throws IllegalAccessError } * TEST: { C o = new C(); o.m()I throws AbstractMethodError } */ public void testPrivateOverrideAbstract() { TestBuilder b = factory.getBuilder(); Interface I = b.intf("I") .abstractMethod("m", "()I").build()
*** 551,588 **** .private_().returns(1).build() .build(); ConcreteClass C = b.clazz("C").implement(J).build(); - Class expectedClass; - if (factory.getExecutionMode().equals("REFLECTION")) { - expectedClass = IllegalAccessException.class; - } else { - expectedClass = IncompatibleClassChangeError.class; - } - b.test().callSite(I, C, "m", "()I").throws_(AbstractMethodError.class).done() ! .test().privateCallSite(J, C, "m", "()I").throws_(expectedClass).done() .test().callSite(C, C, "m", "()I").throws_(AbstractMethodError.class).done() .run(); } /* ! * testPrivateInheritedDefault * * interface I { ! * default private int m() { return 1; } * } * class B implements I {} * class C extends B {} * * TEST: { I o = new C(); o.m()I throws IllegalAccessError } II I.m * -mode reflect throws NoSuchMethodException * TEST: { B o = new C(); o.m()I throws NoSuchMethodError } * TEST: { C o = new C(); o.m()I throws NoSuchMethodError } */ ! public void testPrivateInheritedDefault() { TestBuilder b = factory.getBuilder(); Interface I = b.intf("I") .defaultMethod("m", "()I") .private_().returns(1).build() --- 554,584 ---- .private_().returns(1).build() .build(); ConcreteClass C = b.clazz("C").implement(J).build(); b.test().callSite(I, C, "m", "()I").throws_(AbstractMethodError.class).done() ! .test().privateCallSite(J, C, "m", "()I").throws_(IllegalAccessError.class).done() .test().callSite(C, C, "m", "()I").throws_(AbstractMethodError.class).done() .run(); } /* ! * testPrivateInherited * * interface I { ! * private int m() { return 1; } * } * class B implements I {} * class C extends B {} * * TEST: { I o = new C(); o.m()I throws IllegalAccessError } II I.m * -mode reflect throws NoSuchMethodException * TEST: { B o = new C(); o.m()I throws NoSuchMethodError } * TEST: { C o = new C(); o.m()I throws NoSuchMethodError } */ ! public void testPrivateInherited() { TestBuilder b = factory.getBuilder(); Interface I = b.intf("I") .defaultMethod("m", "()I") .private_().returns(1).build()
*** 605,618 **** .run(); } /* ! * testPrivateDefaultVsConcreteInherited * * interface I { ! * default private int m() { return 1; } * } * class B { * public int m() { return 2; } * } * class C extends B implements I {} --- 601,614 ---- .run(); } /* ! * testPrivateVsConcreteInherited * * interface I { ! * private int m() { return 1; } * } * class B { * public int m() { return 2; } * } * class C extends B implements I {}
*** 620,630 **** * TEST: { I o = new C(); o.m()I == throws IllegalAccessError; } * -mode reflect throws NoSuchMethodException * TEST: { B o = new C(); o.m()I == 2; } * TEST: { C o = new C(); o.m()I == 2; } */ ! public void testPrivateDefaultVsConcreteInherited() { TestBuilder b = factory.getBuilder(); Interface I = b.intf("I") .defaultMethod("m", "()I") .private_().returns(1).build() --- 616,626 ---- * TEST: { I o = new C(); o.m()I == throws IllegalAccessError; } * -mode reflect throws NoSuchMethodException * TEST: { B o = new C(); o.m()I == 2; } * TEST: { C o = new C(); o.m()I == 2; } */ ! public void testPrivateVsConcreteInherited() { TestBuilder b = factory.getBuilder(); Interface I = b.intf("I") .defaultMethod("m", "()I") .private_().returns(1).build()
*** 651,664 **** } /* * testPrivateConflict * ! * Conflicting default methods * * interface I { ! * default private int m() { return 1; } * } * interface J { * default public int m() { return 2; } * } * class C implements I, J {} --- 647,660 ---- } /* * testPrivateConflict * ! * Conflicting methods * * interface I { ! * private int m() { return 1; } * } * interface J { * default public int m() { return 2; } * } * class C implements I, J {}
< prev index next >