Skip to content

Commit

Permalink
Apply non-null strategy to JNIAccessFeature.
Browse files Browse the repository at this point in the history
(cherry picked from commit d996f32)
  • Loading branch information
fniephaus authored and zakkak committed Dec 18, 2023
1 parent ac84791 commit 2b80dd7
Showing 1 changed file with 14 additions and 0 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 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) {
requireNonNull(methods, "methods");
abortIfSealed();
registerConditionalConfiguration(condition, () -> newMethods.addAll(Arrays.asList(methods)));
}

@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 2b80dd7

Please sign in to comment.