Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
8251414: Add test that invokeinterface of a protected method in java.…
…lang.Object throws NoSuchMethodError

Add the missing test cases to existing test InterfaceObjectTest.java

Reviewed-by: lfoltan, coleenp
  • Loading branch information
Harold Seigel committed Aug 14, 2020
1 parent d0b46ec commit 00a596f733657c4283324acdde8f2d45f9202385
@@ -339,7 +339,7 @@ Method* LinkResolver::lookup_method_in_klasses(const LinkInfo& link_info,

// JDK 8, JVMS 5.4.3.4: Interface method resolution should
// ignore static and non-public methods of java.lang.Object,
// like clone, finalize, registerNatives.
// like clone and finalize.
if (in_imethod_resolve &&
result != NULL &&
ik->is_interface() &&
@@ -0,0 +1,84 @@
/*
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

/*
// This jasm file implements the following java code:
interface I { }

public class InterfaceObj implements I {
static void f(I intf) throws Throwable {
I.finalize();
}
public static void testFinalize() throws Throwable {
f(new InterfaceObj());
}
static void c(I intf) throws Throwable {
I.clone();
}
public static void testClone() throws Throwable {
c(new InterfaceObj());
}
}
*/

public interface I version 60:0 { } // end Class I


super public class InterfaceObj implements I version 60:0 {


public Method "<init>":"()V" stack 1 locals 1 {
aload_0;
invokespecial Method java/lang/Object."<init>":"()V";
return;
}

static Method f:"(LI;)V" throws java/lang/Throwable stack 1 locals 1 {
aload_0;
invokeinterface InterfaceMethod I.finalize:"()V", 1;
return;
}

public static Method testFinalize:"()V" throws java/lang/Throwable stack 2 locals 1 {
new class InterfaceObj;
dup;
invokespecial Method "<init>":"()V";
invokestatic Method f:"(LI;)V";
return;
}

static Method c:"(LI;)V" throws java/lang/Throwable stack 1 locals 1 {
aload_0;
invokeinterface InterfaceMethod I.clone:"()Ljava/lang/Object;", 1;
return;
}

public static Method testClone:"()V" throws java/lang/Throwable stack 2 locals 1 {
new class InterfaceObj;
dup;
invokespecial Method "<init>":"()V";
invokestatic Method c:"(LI;)V";
return;
}

} // end Class InterfaceObj
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -23,8 +23,10 @@

/*
* @test
* @bug 8026394
* @summary clone() and finalize() interface resolution should not receive IAE
* @bug 8026394 8251414
* @summary test interface resolution when clone and finalize are declared abstract within
* an interface and when they are not
* @compile InterfaceObj.jasm
* @run main InterfaceObjectTest
*/
interface IClone extends Cloneable {
@@ -54,16 +56,38 @@ public static void tryIt(ICloneExtend o1) {
Object o2 = o1.clone();
o1.finalize();
} catch (Throwable t) {
if (t instanceof IllegalAccessError) {
System.out.println("TEST FAILS - IAE resulted\n");
System.exit(1);
}
throw new AssertionError(t);
}
}

public static void main(String[] args) {

public static void main(String[] args) throws Exception {
// Test with abstract public clone() and finalize() methods.
InterfaceObjectTest o1 = new InterfaceObjectTest();
tryIt(o1);
System.out.println("TEST PASSES - no IAE resulted\n");


// Test with reflection without abstract public clone() and finalize() methods.
Class cls = Class.forName("InterfaceObj");
try {
java.lang.reflect.Method m = cls.getMethod("testFinalize");
m.invoke(cls);
throw new RuntimeException("Failed to throw NoSuchMethodError for finalize()");
} catch (java.lang.reflect.InvocationTargetException e) {
if (!e.getCause().toString().contains("NoSuchMethodError")) {
throw new RuntimeException("wrong ITE: " + e.getCause().toString());
}
}

try {
java.lang.reflect.Method m = cls.getMethod("testClone");
m.invoke(cls);
throw new RuntimeException("Failed to throw NoSuchMethodError for clone()");
} catch (java.lang.reflect.InvocationTargetException e) {
if (!e.getCause().toString().contains("NoSuchMethodError")) {
throw new RuntimeException("wrong ITE: " + e.getCause().toString());
}
}

}
}

0 comments on commit 00a596f

Please sign in to comment.