mirror of
https://github.com/alibaba/testable-mock.git
synced 2025-03-26 01:30:24 +08:00
fix #261, java.net.URL is loaded before OmniClassHandler
This commit is contained in:
parent
63a6a9fdca
commit
6379f16266
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user