Skip to content

Commit 953d378

Browse files
Read the class name from the bytecode if the class name is null during class definition.
Make ClassLoader#findLoadedClass0 compatible with JDK implementation.
1 parent a35d0c6 commit 953d378

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/hub/registry/ClassRegistries.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -300,13 +300,17 @@ public static Class<?> defineClass(ClassLoader loader, String name, byte[] b, in
300300
// The defineClass path usually can't throw ClassNotFoundException
301301
throw sneakyThrow(new ClassNotFoundException(name));
302302
}
303-
ByteSequence typeBytes = ByteSequence.createTypeFromName(name);
304-
Symbol<Type> type = SymbolsSupport.getTypes().getOrCreateValidType(typeBytes);
305-
if (type == null) {
306-
throw new NoClassDefFoundError(name);
307-
}
308303
AbstractRuntimeClassRegistry registry = (AbstractRuntimeClassRegistry) singleton().getRegistry(loader);
309-
return registry.defineClass(type, b, off, len, info);
304+
if (name != null) {
305+
ByteSequence typeBytes = ByteSequence.createTypeFromName(name);
306+
Symbol<Type> type = SymbolsSupport.getTypes().getOrCreateValidType(typeBytes);
307+
if (type == null) {
308+
throw new NoClassDefFoundError(name);
309+
}
310+
return registry.defineClass(type, b, off, len, info);
311+
} else {
312+
return registry.defineClass(null, b, off, len, info);
313+
}
310314
}
311315

312316
@SuppressWarnings("unchecked")

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_java_lang_ClassLoader.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,10 @@ Class<?> loadClass(Module module, String name) {
199199
@BasedOnJDKFile("https://github.com/openjdk/jdk/blob/jdk-25+16/src/hotspot/share/prims/jvm.cpp#L1056-L1096")
200200
@SuppressWarnings({"unused"}) //
201201
private Class<?> findLoadedClass0(String name) {
202+
if (name == null) {
203+
return null;
204+
}
205+
202206
/*
203207
* HotSpot supports both dot- and slash-names here as well as array types The only caller
204208
* (findLoadedClass) errors out on slash-names and array types so we assume dot-names

0 commit comments

Comments
 (0)