fix: JVM error when instantiating certain types

This commit is contained in:
Dan Mulloy 2024-06-13 19:49:24 -05:00
parent e726f6eb0d
commit a006b70c6f
No known key found for this signature in database
GPG Key ID: 3C5AD5D866D1539A

View File

@ -3,6 +3,10 @@ package com.comphenix.protocol.reflect.instances;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.nio.ByteBuffer;
import java.nio.FloatBuffer;
import java.util.Map;
import java.util.WeakHashMap;
import java.util.function.Supplier;
import com.comphenix.protocol.reflect.accessors.Accessors;
@ -10,6 +14,16 @@ import com.comphenix.protocol.reflect.accessors.ConstructorAccessor;
import com.comphenix.protocol.reflect.accessors.MethodAccessor;
public final class InstanceCreator implements Supplier<Object> {
private static Map<Class<?>, Object> BANNED_PARAMETERS = new WeakHashMap<>();
static {
try {
BANNED_PARAMETERS.put(ByteBuffer.class, true);
BANNED_PARAMETERS.put(FloatBuffer.class, true);
} catch (Throwable ignored) {
}
}
private ConstructorAccessor constructor = null;
private MethodAccessor factoryMethod = null;
private Class<?>[] paramTypes = null;
@ -45,6 +59,15 @@ public final class InstanceCreator implements Supplier<Object> {
return params;
}
private boolean containsBannedParameter(Class<?>[] paramTypes) {
for (Class<?> paramType : paramTypes) {
if (BANNED_PARAMETERS.containsKey(paramType)) {
return true;
}
}
return false;
}
@Override
public Object get() {
Object[] params = paramTypes != null ? createParams(paramTypes) : null;
@ -70,6 +93,10 @@ public final class InstanceCreator implements Supplier<Object> {
continue;
}
if (containsBannedParameter(paramTypes)) {
continue;
}
Object[] testParams = createParams(paramTypes);
try {
@ -103,6 +130,10 @@ public final class InstanceCreator implements Supplier<Object> {
continue;
}
if (containsBannedParameter(paramTypes)) {
continue;
}
Object[] testParams = createParams(paramTypes);
try {