-
Bug
-
Resolution: Not an Issue
-
P3
-
8, 10, 11
not initialized. This prevents reloading of the uninitialized class in our
application.
Consider the test case:
public class Main {
public static void foo(Foo f) {
}
public static void main(String[] args) throws ClassNotFoundException {
//load class, but don't initialize it
Class.forName("Foo", false, Main.class.getClassLoader());
//alternative: call Main.class.getMethods();
new Foo().bar(); // breakpoint here
}
}
class Foo {
static {
System.out.println("Foo initialized");
}
void bar() {
System.out.println("yy");
}
}
When debugger stops at breakpoint, where Foo is loaded but not initialized,
VirtualMachine.allClasses() does not contain a class Foo as it should,
according to
https://docs.oracle.com/javase/8/docs/jdk/api/jpda/jdi/com/sun/jdi/VirtualMachine.html#allClasses()
jdk1.8.0_131\bin\jdb" Main
Initializing jdb ...
> stop at Main:9
Deferring breakpoint Main:9.
It will be set after the class is loaded.
> run
run Main
Set uncaught java.lang.Throwable
Set deferred uncaught java.lang.Throwable
>
VM Started: Set deferred breakpoint Main:9
Breakpoint hit: "thread=main", Main.main(), line=9 bci=12
9 new Foo().bar(); // breakpoint here
main[1] class Foo
"Foo" is not a valid id or class name.
main[1]
It's not until we initialize Foo that it is then returned by
VirtualMachine.allClasses():
main[1] step
>
Step completed: "thread=main", Foo.<clinit>(), line=16 bci=0
16 System.out.println("Foo initialized");
main[1] class Foo
Class: Foo
extends: java.lang.Object
- duplicates
-
JDK-8233272 The Class.forName specification should be updated to match the long-standing implementation with respect to class linking
-
- Closed
-
-
JDK-8227926 add new JVM TI and JDI tests for classes loaded by Class::forName
-
- Closed
-
- relates to
-
JDK-8212117 Class.forName may return a reference to a loaded but not linked Class
-
- Resolved
-
-
JDK-8267525 add test for non-linked classes are not returned by VirtualMachine.allClasses
-
- Closed
-
-
JDK-8205061 JVMTI GetClassFields/Methods return jfield/methodIDs without class init
-
- Open
-
-
JDK-8233091 Backout JDK-8212117: Class.forName loads a class but not linked if class is not initialized
-
- Resolved
-