Skip to content

Commit a006b70

Browse files
committed
fix: JVM error when instantiating certain types
1 parent e726f6e commit a006b70

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

src/main/java/com/comphenix/protocol/reflect/instances/InstanceCreator.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,27 @@
33
import java.lang.reflect.Constructor;
44
import java.lang.reflect.Method;
55
import java.lang.reflect.Modifier;
6+
import java.nio.ByteBuffer;
7+
import java.nio.FloatBuffer;
8+
import java.util.Map;
9+
import java.util.WeakHashMap;
610
import java.util.function.Supplier;
711

812
import com.comphenix.protocol.reflect.accessors.Accessors;
913
import com.comphenix.protocol.reflect.accessors.ConstructorAccessor;
1014
import com.comphenix.protocol.reflect.accessors.MethodAccessor;
1115

1216
public final class InstanceCreator implements Supplier<Object> {
17+
private static Map<Class<?>, Object> BANNED_PARAMETERS = new WeakHashMap<>();
18+
19+
static {
20+
try {
21+
BANNED_PARAMETERS.put(ByteBuffer.class, true);
22+
BANNED_PARAMETERS.put(FloatBuffer.class, true);
23+
} catch (Throwable ignored) {
24+
}
25+
}
26+
1327
private ConstructorAccessor constructor = null;
1428
private MethodAccessor factoryMethod = null;
1529
private Class<?>[] paramTypes = null;
@@ -45,6 +59,15 @@ private Object[] createParams(Class<?>[] paramTypes) {
4559
return params;
4660
}
4761

62+
private boolean containsBannedParameter(Class<?>[] paramTypes) {
63+
for (Class<?> paramType : paramTypes) {
64+
if (BANNED_PARAMETERS.containsKey(paramType)) {
65+
return true;
66+
}
67+
}
68+
return false;
69+
}
70+
4871
@Override
4972
public Object get() {
5073
Object[] params = paramTypes != null ? createParams(paramTypes) : null;
@@ -70,6 +93,10 @@ public Object get() {
7093
continue;
7194
}
7295

96+
if (containsBannedParameter(paramTypes)) {
97+
continue;
98+
}
99+
73100
Object[] testParams = createParams(paramTypes);
74101

75102
try {
@@ -103,6 +130,10 @@ public Object get() {
103130
continue;
104131
}
105132

133+
if (containsBannedParameter(paramTypes)) {
134+
continue;
135+
}
136+
106137
Object[] testParams = createParams(paramTypes);
107138

108139
try {

0 commit comments

Comments
 (0)