Skip to content

Commit

Permalink
Apply non-null strategy to JNIAccessFeature.
Browse files Browse the repository at this point in the history
  • Loading branch information
fniephaus committed Nov 2, 2023
1 parent f94551a commit d996f32
Showing 1 changed file with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.util.IdentityHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Predicate;
Expand All @@ -42,9 +43,6 @@
import org.graalvm.collections.EconomicSet;
import org.graalvm.collections.Equivalence;
import org.graalvm.collections.UnmodifiableMapCursor;
import jdk.graal.compiler.api.replacements.Fold;
import jdk.graal.compiler.options.Option;
import jdk.graal.compiler.word.WordTypes;
import org.graalvm.nativeimage.ImageSingletons;
import org.graalvm.nativeimage.c.function.CodePointer;
import org.graalvm.nativeimage.hosted.Feature;
Expand Down Expand Up @@ -98,6 +96,9 @@
import com.oracle.svm.hosted.substitute.SubstitutionReflectivityFilter;
import com.oracle.svm.util.ReflectionUtil;

import jdk.graal.compiler.api.replacements.Fold;
import jdk.graal.compiler.options.Option;
import jdk.graal.compiler.word.WordTypes;
import jdk.vm.ci.meta.MetaAccessProvider;
import jdk.vm.ci.meta.ResolvedJavaField;
import jdk.vm.ci.meta.ResolvedJavaMethod;
Expand Down Expand Up @@ -202,18 +203,21 @@ private class JNIRuntimeAccessibilitySupportImpl extends ConditionalConfiguratio
@Override
public void register(ConfigurationCondition condition, boolean unsafeAllocated, Class<?> clazz) {
assert !unsafeAllocated : "unsafeAllocated can be only set via Unsafe.allocateInstance, not via JNI.";
Objects.requireNonNull(clazz, () -> nullErrorMessage("class"));
abortIfSealed();
registerConditionalConfiguration(condition, () -> newClasses.add(clazz));
}

@Override
public void register(ConfigurationCondition condition, boolean queriedOnly, Executable... methods) {
public void register(ConfigurationCondition condition, boolean queriedOnly, Executable... executables) {
requireNonNull(executables, "executable");
abortIfSealed();
registerConditionalConfiguration(condition, () -> newMethods.addAll(Arrays.asList(methods)));
registerConditionalConfiguration(condition, () -> newMethods.addAll(Arrays.asList(executables)));
}

@Override
public void register(ConfigurationCondition condition, boolean finalIsWritable, Field... fields) {
requireNonNull(fields, "field");
abortIfSealed();
registerConditionalConfiguration(condition, () -> registerFields(finalIsWritable, fields));
}
Expand Down Expand Up @@ -622,4 +626,14 @@ private static boolean anyFieldMatches(ResolvedJavaType sub, String name) {
return false;
}
}

private static void requireNonNull(Object[] values, String kind) {
for (Object value : values) {
Objects.requireNonNull(value, () -> nullErrorMessage(kind));
}
}

private static String nullErrorMessage(String kind) {
return "Cannot register null value as " + kind + " for JNI access. Please ensure that all values you register are not null.";
}
}

0 comments on commit d996f32

Please sign in to comment.