3
3
import java .lang .reflect .Constructor ;
4
4
import java .lang .reflect .Method ;
5
5
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 ;
6
10
import java .util .function .Supplier ;
7
11
8
12
import com .comphenix .protocol .reflect .accessors .Accessors ;
9
13
import com .comphenix .protocol .reflect .accessors .ConstructorAccessor ;
10
14
import com .comphenix .protocol .reflect .accessors .MethodAccessor ;
11
15
12
16
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
+
13
27
private ConstructorAccessor constructor = null ;
14
28
private MethodAccessor factoryMethod = null ;
15
29
private Class <?>[] paramTypes = null ;
@@ -45,6 +59,15 @@ private Object[] createParams(Class<?>[] paramTypes) {
45
59
return params ;
46
60
}
47
61
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
+
48
71
@ Override
49
72
public Object get () {
50
73
Object [] params = paramTypes != null ? createParams (paramTypes ) : null ;
@@ -70,6 +93,10 @@ public Object get() {
70
93
continue ;
71
94
}
72
95
96
+ if (containsBannedParameter (paramTypes )) {
97
+ continue ;
98
+ }
99
+
73
100
Object [] testParams = createParams (paramTypes );
74
101
75
102
try {
@@ -103,6 +130,10 @@ public Object get() {
103
130
continue ;
104
131
}
105
132
133
+ if (containsBannedParameter (paramTypes )) {
134
+ continue ;
135
+ }
136
+
106
137
Object [] testParams = createParams (paramTypes );
107
138
108
139
try {
0 commit comments