Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,7 @@ private static void arrayHubErrorStub(DynamicHub elementType) {
} else if (elementType == DynamicHub.fromClass(void.class)) {
throw new IllegalArgumentException("Cannot allocate void array.");
} else if (elementType.getArrayHub() == null || !elementType.getArrayHub().isInstantiated()) {
throw new IllegalArgumentException("Class " + DynamicHub.toClass(elementType).getTypeName() + "[] is instantiated reflectively but was never registered." +
"Register the class by adding \"unsafeAllocated\" for the class in " + ConfigurationFile.REFLECTION.getFileName() + ".");
throw MissingReflectionRegistrationUtils.errorForArray(DynamicHub.toClass(elementType), 1);
} else {
VMError.shouldNotReachHereUnexpectedInput(elementType); // ExcludeFromJacocoGeneratedReport
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import java.lang.reflect.Array;
import java.util.Objects;

import jdk.graal.compiler.word.BarrieredAccess;
import org.graalvm.word.UnsignedWord;

import com.oracle.svm.core.SubstrateUtil;
Expand All @@ -38,7 +37,9 @@
import com.oracle.svm.core.config.ConfigurationValues;
import com.oracle.svm.core.hub.DynamicHub;
import com.oracle.svm.core.hub.LayoutEncoding;
import com.oracle.svm.core.util.VMError;
import com.oracle.svm.core.reflect.MissingReflectionRegistrationUtils;

import jdk.graal.compiler.word.BarrieredAccess;

@TargetClass(java.lang.reflect.Array.class)
final class Target_java_lang_reflect_Array {
Expand Down Expand Up @@ -406,7 +407,7 @@ private static Object multiNewArray(Class<?> componentType, int[] dimensions) {
for (int i = 0; i < dimensions.length; i++) {
arrayHub = arrayHub.getArrayHub();
if (arrayHub == null) {
throw VMError.unsupportedFeature("Cannot allocate " + dimensions.length + "-dimensional array of " + componentType.getName());
throw MissingReflectionRegistrationUtils.errorForArray(componentType, dimensions.length);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,19 @@ public static MissingReflectionRegistrationError errorForProxy(Class<?>... inter
return exception;
}

public static MissingReflectionRegistrationError errorForArray(Class<?> elementClass, int dimension) {
MissingReflectionRegistrationError exception = new MissingReflectionRegistrationError(errorMessage("instantiate the array class",
elementClass.getTypeName() + "[]".repeat(dimension),
"Add \"unsafeAllocated\" to the array class registration to enable runtime instantiation.", "reflection"),
null, null, null, null);
report(exception);
/*
* If report doesn't throw, we throw the exception anyway since this is a Native
* Image-specific error that is unrecoverable in any case.
*/
return exception;
}

private static String errorMessage(String failedAction, String elementDescriptor) {
return errorMessage(failedAction, elementDescriptor, null, "reflection");
}
Expand Down