Skip to content

Commit

Permalink
Improve exception handling with Java 23
Browse files Browse the repository at this point in the history
  • Loading branch information
bwaldvogel committed Dec 29, 2024
1 parent 0f12c2e commit 5b79512
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/main/java/de/cronn/reflection/util/PropertyUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.lang.annotation.Annotation;
import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.Collections;
Expand All @@ -16,6 +17,7 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.VisibleForTesting;
import org.objenesis.ObjenesisException;
import org.objenesis.ObjenesisHelper;

public final class PropertyUtils {
Expand Down Expand Up @@ -333,6 +335,13 @@ private static <T> T createProxy(Class<T> beanClass, MethodCaptor methodCaptor)
T proxyInstance = ObjenesisHelper.newInstance(proxyClass);
writeDirectly(proxyInstance, MethodCaptor.FIELD_NAME, methodCaptor);
return proxyInstance;
} catch (ObjenesisException e) {
if (e.getCause() instanceof InvocationTargetException invocationTargetException) {
if (invocationTargetException.getTargetException() instanceof IllegalAccessError illegalAccessError) {
throw new ReflectionRuntimeException("Failed to create proxy on " + beanClass, illegalAccessError);
}
}
throw e;
} catch (IllegalAccessError e) {
throw new ReflectionRuntimeException("Failed to create proxy on " + beanClass, e);
}
Expand Down

0 comments on commit 5b79512

Please sign in to comment.