diff --git a/core/deployment/src/main/java/io/quarkus/deployment/ExtensionLoader.java b/core/deployment/src/main/java/io/quarkus/deployment/ExtensionLoader.java index d4076b42abab7..c860703638fa8 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/ExtensionLoader.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/ExtensionLoader.java @@ -13,6 +13,7 @@ import static java.util.Arrays.asList; import java.io.IOException; +import java.lang.invoke.MethodHandles; import java.lang.reflect.AnnotatedElement; import java.lang.reflect.Constructor; import java.lang.reflect.Field; @@ -23,6 +24,7 @@ import java.lang.reflect.Parameter; import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; +import java.lang.reflect.UndeclaredThrowableException; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -432,6 +434,7 @@ private static Consumer loadStepsFromClass(Class clazz, final List methods = getMethods(clazz); final Map> nameToMethods = methods.stream().collect(Collectors.groupingBy(m -> m.getName())); + MethodHandles.Lookup lookup = MethodHandles.publicLookup(); for (Method method : methods) { final BuildStep buildStep = method.getAnnotation(BuildStep.class); if (buildStep == null) { @@ -846,17 +849,13 @@ public void execute(final BuildContext bc) { } Object result; try { - result = method.invoke(instance, methodArgs); + result = lookup.unreflect(method).bindTo(instance).invokeWithArguments(methodArgs); } catch (IllegalAccessException e) { throw ReflectUtil.toError(e); - } catch (InvocationTargetException e) { - try { - throw e.getCause(); - } catch (RuntimeException | Error e2) { - throw e2; - } catch (Throwable t) { - throw new IllegalStateException(t); - } + } catch (RuntimeException | Error e2) { + throw e2; + } catch (Throwable t) { + throw new UndeclaredThrowableException(t); } resultConsumer.accept(bc, result); if (isRecorder) {