Skip to content

Commit 5b79512

Browse files
committed
Improve exception handling with Java 23
1 parent 0f12c2e commit 5b79512

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/main/java/de/cronn/reflection/util/PropertyUtils.java

+9
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.lang.annotation.Annotation;
55
import java.lang.reflect.AccessibleObject;
66
import java.lang.reflect.Field;
7+
import java.lang.reflect.InvocationTargetException;
78
import java.lang.reflect.Method;
89
import java.util.Collection;
910
import java.util.Collections;
@@ -16,6 +17,7 @@
1617
import org.jetbrains.annotations.NotNull;
1718
import org.jetbrains.annotations.Nullable;
1819
import org.jetbrains.annotations.VisibleForTesting;
20+
import org.objenesis.ObjenesisException;
1921
import org.objenesis.ObjenesisHelper;
2022

2123
public final class PropertyUtils {
@@ -333,6 +335,13 @@ private static <T> T createProxy(Class<T> beanClass, MethodCaptor methodCaptor)
333335
T proxyInstance = ObjenesisHelper.newInstance(proxyClass);
334336
writeDirectly(proxyInstance, MethodCaptor.FIELD_NAME, methodCaptor);
335337
return proxyInstance;
338+
} catch (ObjenesisException e) {
339+
if (e.getCause() instanceof InvocationTargetException invocationTargetException) {
340+
if (invocationTargetException.getTargetException() instanceof IllegalAccessError illegalAccessError) {
341+
throw new ReflectionRuntimeException("Failed to create proxy on " + beanClass, illegalAccessError);
342+
}
343+
}
344+
throw e;
336345
} catch (IllegalAccessError e) {
337346
throw new ReflectionRuntimeException("Failed to create proxy on " + beanClass, e);
338347
}

0 commit comments

Comments
 (0)