mirror of
https://github.com/dmulloy2/ProtocolLib.git
synced 2024-11-27 05:05:24 +01:00
fix: JVM error when instantiating certain types
This commit is contained in:
parent
e726f6eb0d
commit
a006b70c6f
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user