Fix exception on Field#getGenericType (#42)
This commit is contained in:
parent
c5b9b05132
commit
a401ef3111
|
@ -82,52 +82,77 @@ public class ClassLoaderRemapper extends JarRemapper {
|
||||||
private final Map<String, Boolean> cacheRemap = new ConcurrentHashMap<>();
|
private final Map<String, Boolean> cacheRemap = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
private Map.Entry<Map<Method, String>, Map<WrappedMethod, Method>> getMethods(Class<?> cl, String internalName) {
|
private Map.Entry<Map<Method, String>, Map<WrappedMethod, Method>> getMethods(Class<?> cl, String internalName) {
|
||||||
return cacheMethods.computeIfAbsent(internalName, k -> this.tryGetMethods(cl, k));
|
return cacheMethods.computeIfAbsent(internalName, k -> this.tryGetMethods(cl));
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map.Entry<Map<Method, String>, Map<WrappedMethod, Method>> tryGetMethods(Class<?> cl, String internalName) {
|
private Map.Entry<Map<Method, String>, Map<WrappedMethod, Method>> tryGetMethods(Class<?> cl) {
|
||||||
try {
|
try {
|
||||||
Map<Method, String> names = new HashMap<>();
|
Map<Method, String> names = new HashMap<>();
|
||||||
Map<WrappedMethod, Method> types = new HashMap<>();
|
Map<WrappedMethod, Method> types = new HashMap<>();
|
||||||
for (Method method : cl.getMethods()) {
|
for (Method method : cl.getMethods()) {
|
||||||
|
checkMethodTypes(method);
|
||||||
String name = mapMethod(method);
|
String name = mapMethod(method);
|
||||||
names.put(method, name);
|
names.put(method, name);
|
||||||
WrappedMethod wrapped = new WrappedMethod(name, method.getParameterTypes());
|
WrappedMethod wrapped = new WrappedMethod(name, method.getParameterTypes());
|
||||||
types.put(wrapped, method);
|
types.put(wrapped, method);
|
||||||
}
|
}
|
||||||
for (Method method : cl.getDeclaredMethods()) {
|
for (Method method : cl.getDeclaredMethods()) {
|
||||||
|
checkMethodTypes(method);
|
||||||
String name = mapMethod(method);
|
String name = mapMethod(method);
|
||||||
names.put(method, name);
|
names.put(method, name);
|
||||||
WrappedMethod wrapped = new WrappedMethod(name, method.getParameterTypes());
|
WrappedMethod wrapped = new WrappedMethod(name, method.getParameterTypes());
|
||||||
types.put(wrapped, method);
|
types.put(wrapped, method);
|
||||||
}
|
}
|
||||||
return Maps.immutableEntry(names, types);
|
return Maps.immutableEntry(names, types);
|
||||||
|
} catch (TypeNotPresentException e) {
|
||||||
|
if (e.getCause() instanceof ClassNotFoundException) {
|
||||||
|
tryDefineClass(e.getCause().getMessage().replace('.', '/'));
|
||||||
|
return tryGetMethods(cl);
|
||||||
|
} else throw e;
|
||||||
} catch (NoClassDefFoundError error) {
|
} catch (NoClassDefFoundError error) {
|
||||||
tryDefineClass(error.getMessage());
|
tryDefineClass(error.getMessage());
|
||||||
return tryGetMethods(cl, internalName);
|
return tryGetMethods(cl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private BiMap<Field, String> getFields(Class<?> cl, String internalName) {
|
private BiMap<Field, String> getFields(Class<?> cl, String internalName) {
|
||||||
return cacheFields.computeIfAbsent(internalName, k -> this.tryGetFields(cl, k));
|
return cacheFields.computeIfAbsent(internalName, k -> this.tryGetFields(cl));
|
||||||
}
|
}
|
||||||
|
|
||||||
private BiMap<Field, String> tryGetFields(Class<?> cl, String internalName) {
|
private BiMap<Field, String> tryGetFields(Class<?> cl) {
|
||||||
try {
|
try {
|
||||||
HashBiMap<Field, String> map = HashBiMap.create();
|
HashBiMap<Field, String> map = HashBiMap.create();
|
||||||
for (Field field : cl.getFields()) {
|
for (Field field : cl.getFields()) {
|
||||||
|
checkFieldTypes(field);
|
||||||
map.forcePut(field, mapField(field));
|
map.forcePut(field, mapField(field));
|
||||||
}
|
}
|
||||||
for (Field field : cl.getDeclaredFields()) {
|
for (Field field : cl.getDeclaredFields()) {
|
||||||
|
checkFieldTypes(field);
|
||||||
map.forcePut(field, mapField(field));
|
map.forcePut(field, mapField(field));
|
||||||
}
|
}
|
||||||
return map;
|
return map;
|
||||||
|
} catch (TypeNotPresentException e) {
|
||||||
|
if (e.getCause() instanceof ClassNotFoundException) {
|
||||||
|
tryDefineClass(e.getCause().getMessage().replace('.', '/'));
|
||||||
|
return tryGetFields(cl);
|
||||||
|
} else throw e;
|
||||||
} catch (NoClassDefFoundError error) {
|
} catch (NoClassDefFoundError error) {
|
||||||
tryDefineClass(error.getMessage());
|
tryDefineClass(error.getMessage());
|
||||||
return tryGetFields(cl, internalName);
|
return tryGetFields(cl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("ResultOfMethodCallIgnored")
|
||||||
|
private void checkFieldTypes(Field field) throws TypeNotPresentException {
|
||||||
|
field.getGenericType();
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("ResultOfMethodCallIgnored")
|
||||||
|
private void checkMethodTypes(Method method) throws TypeNotPresentException {
|
||||||
|
method.getGenericReturnType();
|
||||||
|
method.getGenericParameterTypes();
|
||||||
|
}
|
||||||
|
|
||||||
private void tryDefineClass(String internalName) {
|
private void tryDefineClass(String internalName) {
|
||||||
if (!internalName.startsWith(PREFIX)) {
|
if (!internalName.startsWith(PREFIX)) {
|
||||||
throw new NoClassDefFoundError(internalName);
|
throw new NoClassDefFoundError(internalName);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user