-
Bug
-
Resolution: Not an Issue
-
P4
-
10
The following program crashes when trying to redefine the class' private method during resolution of the bootstrap method used within that private method. The bootstrap method is being resolved resulting from the private method containing an invokedynamic instruction.
==============================================
/*
* @test
* @library /test/lib
* @modules java.base/jdk.internal.misc
* @modules java.compiler
* java.instrument
* jdk.jartool/sun.tools.jar
* @run main RedefineClassHelper
* @run main/othervm -javaagent:redefineagent.jar -Xlog:redefine+class*=trace RedefineInterfaceMethods
*/
public class RedefineInterfaceMethods {
static final int RET = -2;
static interface B {
int ORIGINAL_RETURN = 1;
int NEW_RETURN = 2;
private int privateMethod() {
Runnable race1 = () -> System.out.println("Hello from inside privateMethod");
race1.run();
return ORIGINAL_RETURN;
}
public default int defaultMethod(String p) {
return privateMethod();
}
}
public static String redefinedPrivateMethod =
"interface RedefineInterfaceMethods$B {" +
" int ORIGINAL_RETURN = 1;" +
" int NEW_RETURN = 2;" +
" private int privateMethod() {" +
" Runnable race1 = () -> System.out.println(\"Hello from inside privateMethod\");" +
" race1.run();" +
" return NEW_RETURN;" +
" }" +
" public default int defaultMethod(String p) {" +
// " System.out.println(p + \"from interface B's defaultMethod\");" +
" return privateMethod();" +
" }" +
"}";
static class Impl implements B {
}
public static void main(String[] args) throws Exception {
Impl impl = new Impl();
int res = impl.defaultMethod("Hello ");
if (res != B.ORIGINAL_RETURN)
throw new Error("defaultMethod returned " + res +
" expected " + B.ORIGINAL_RETURN);
RedefineClassHelper.redefineClass(B.class, redefinedPrivateMethod);
res = impl.defaultMethod("Goodbye ");
if (res != B.NEW_RETURN)
throw new Error("defaultMethod returned " + res +
" expected " + B.NEW_RETURN);
}
}
==============================================
/*
* @test
* @library /test/lib
* @modules java.base/jdk.internal.misc
* @modules java.compiler
* java.instrument
* jdk.jartool/sun.tools.jar
* @run main RedefineClassHelper
* @run main/othervm -javaagent:redefineagent.jar -Xlog:redefine+class*=trace RedefineInterfaceMethods
*/
public class RedefineInterfaceMethods {
static final int RET = -2;
static interface B {
int ORIGINAL_RETURN = 1;
int NEW_RETURN = 2;
private int privateMethod() {
Runnable race1 = () -> System.out.println("Hello from inside privateMethod");
race1.run();
return ORIGINAL_RETURN;
}
public default int defaultMethod(String p) {
return privateMethod();
}
}
public static String redefinedPrivateMethod =
"interface RedefineInterfaceMethods$B {" +
" int ORIGINAL_RETURN = 1;" +
" int NEW_RETURN = 2;" +
" private int privateMethod() {" +
" Runnable race1 = () -> System.out.println(\"Hello from inside privateMethod\");" +
" race1.run();" +
" return NEW_RETURN;" +
" }" +
" public default int defaultMethod(String p) {" +
// " System.out.println(p + \"from interface B's defaultMethod\");" +
" return privateMethod();" +
" }" +
"}";
static class Impl implements B {
}
public static void main(String[] args) throws Exception {
Impl impl = new Impl();
int res = impl.defaultMethod("Hello ");
if (res != B.ORIGINAL_RETURN)
throw new Error("defaultMethod returned " + res +
" expected " + B.ORIGINAL_RETURN);
RedefineClassHelper.redefineClass(B.class, redefinedPrivateMethod);
res = impl.defaultMethod("Goodbye ");
if (res != B.NEW_RETURN)
throw new Error("defaultMethod returned " + res +
" expected " + B.NEW_RETURN);
}
}
- relates to
-
JDK-8225325 Add tests for redefining a class' private method during resolution of the bootstrap specifier
- Resolved