mirror of
https://github.com/dmulloy2/ProtocolLib.git
synced 2025-02-18 21:41:48 +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.Constructor;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.lang.reflect.Modifier;
|
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 java.util.function.Supplier;
|
||||||
|
|
||||||
import com.comphenix.protocol.reflect.accessors.Accessors;
|
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;
|
import com.comphenix.protocol.reflect.accessors.MethodAccessor;
|
||||||
|
|
||||||
public final class InstanceCreator implements Supplier<Object> {
|
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 ConstructorAccessor constructor = null;
|
||||||
private MethodAccessor factoryMethod = null;
|
private MethodAccessor factoryMethod = null;
|
||||||
private Class<?>[] paramTypes = null;
|
private Class<?>[] paramTypes = null;
|
||||||
@ -45,6 +59,15 @@ public final class InstanceCreator implements Supplier<Object> {
|
|||||||
return params;
|
return params;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean containsBannedParameter(Class<?>[] paramTypes) {
|
||||||
|
for (Class<?> paramType : paramTypes) {
|
||||||
|
if (BANNED_PARAMETERS.containsKey(paramType)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object get() {
|
public Object get() {
|
||||||
Object[] params = paramTypes != null ? createParams(paramTypes) : null;
|
Object[] params = paramTypes != null ? createParams(paramTypes) : null;
|
||||||
@ -70,6 +93,10 @@ public final class InstanceCreator implements Supplier<Object> {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (containsBannedParameter(paramTypes)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
Object[] testParams = createParams(paramTypes);
|
Object[] testParams = createParams(paramTypes);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -103,6 +130,10 @@ public final class InstanceCreator implements Supplier<Object> {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (containsBannedParameter(paramTypes)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
Object[] testParams = createParams(paramTypes);
|
Object[] testParams = createParams(paramTypes);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
Loading…
Reference in New Issue
Block a user