From c66d655beabaf79eed109621b71d343a4eb09cfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillermo=20Rodr=C3=ADguez?= Date: Mon, 17 Aug 2026 14:51:04 +0200 Subject: [PATCH] OpenJDK: Fix long array creation in JVM_NewMultiArray MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When JamVM is built for OpenJDK, Array.newInstance(Class, int[]) is mapped to the internal function JVM_NewMultiArray. JVM_NewMultiArray constructs an array class descriptor from a local primitive-type table. The table incorrectly maps long to 'L' instead of 'J'. As a result, the generated array class name (e.g. "[[L") is invalid, and the VM may crash while resolving it. Fix by replacing the table in JVM_NewMultiArray with a call to the existing primClass2TypeChar() helper, which has the correct mapping. Signed-off-by: Guillermo Rodríguez --- src/classlib/openjdk/jvm.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/classlib/openjdk/jvm.c b/src/classlib/openjdk/jvm.c index 27c5029..c6a4a6a 100644 --- a/src/classlib/openjdk/jvm.c +++ b/src/classlib/openjdk/jvm.c @@ -2206,8 +2206,6 @@ jobject JVM_NewMultiArray(JNIEnv *env, jclass eltClass, jintArray dim) { need to convert from primitive class name to primitive char (e.g. "int" -> "I") */ - static char type_name[] = {'Z', 'B', 'C', 'S', - 'I', 'F', 'L', 'D'}; int type = getPrimTypeIndex(cb); if(type == PRIM_IDX_VOID) { @@ -2218,7 +2216,7 @@ jobject JVM_NewMultiArray(JNIEnv *env, jclass eltClass, jintArray dim) { /* Construct primitive array name, e.g. "[[I" */ array_name = alloca(len + 2); - array_name[len] = type_name[type - 1]; + array_name[len] = primClass2TypeChar((Class*)eltClass); array_name[len + 1] = '\0'; } else { /* Construct object array name, e.g. "[[Ljava/lang/String;" */