fix , java.net.URL is loaded before OmniClassHandler

This commit is contained in:
金戟 2022-02-02 16:50:52 +08:00
parent 63a6a9fdca
commit 6379f16266

View File

@ -227,6 +227,10 @@ public class OmniConstructor {
private static Object createInstance(Class<?> clazz, Set<Class<?>> classPool)
throws InstantiationException, IllegalAccessException, InvocationTargetException {
Object ins = createSpecialClass(clazz);
if (ins != null) {
return ins;
}
Constructor<?> constructor = getBestConstructor(clazz);
if (constructor == null) {
throw new ClassConstructionException("Fail to invoke constructor of " + clazz.getName());
@ -244,6 +248,18 @@ public class OmniConstructor {
}
}
private static Object createSpecialClass(Class<?> clazz) throws InstantiationException, IllegalAccessException, InvocationTargetException {
try {
// java.net.URL is loaded before OmniClassHandler, cannot be instrumented
if (clazz.getName().equals("java.net.URL")) {
return clazz.getDeclaredConstructor(String.class).newInstance("https://");
}
} catch (NoSuchMethodException e) {
return null;
}
return null;
}
private static Constructor<?> getBestConstructor(Class<?> clazz) {
Constructor<?> bestConstructor = null;
int minimalExceptionCount = 999;