diff --git a/core/runtime/src/main/java/io/quarkus/runtime/Quarkus.java b/core/runtime/src/main/java/io/quarkus/runtime/Quarkus.java index d58d2641dc2c2..dc54e1fdcf309 100644 --- a/core/runtime/src/main/java/io/quarkus/runtime/Quarkus.java +++ b/core/runtime/src/main/java/io/quarkus/runtime/Quarkus.java @@ -2,6 +2,10 @@ import java.io.Closeable; import java.io.IOException; +import java.lang.invoke.MethodHandle; +import java.lang.invoke.MethodHandles; +import java.lang.invoke.MethodType; +import java.lang.reflect.UndeclaredThrowableException; import java.util.Locale; import java.util.function.BiConsumer; @@ -67,18 +71,17 @@ public static void run(Class quarkusApplication, B //we already have an application, run it directly Class appClass = (Class) Class.forName(Application.APP_CLASS_NAME, false, Thread.currentThread().getContextClassLoader()); - Application application = appClass.getDeclaredConstructor().newInstance(); + MethodHandle constructor = MethodHandles.lookup().findConstructor(appClass, MethodType.methodType(void.class)); + Application application = (Application) constructor.invoke(); ApplicationLifecycleManager.run(application, quarkusApplication, exitHandler, args); return; } catch (ClassNotFoundException e) { //ignore, this happens when running in dev mode - } catch (Exception e) { - if (exitHandler != null) { - exitHandler.accept(1, e); - } else { - Logger.getLogger(Quarkus.class).error("Error running Quarkus", e); - ApplicationLifecycleManager.getDefaultExitCodeHandler().accept(1, e); - } + } catch (RuntimeException | Error e) { + handleReflectiveInvocationIssue(exitHandler, e); + return; + } catch (Throwable t) { + handleReflectiveInvocationIssue(exitHandler, new UndeclaredThrowableException(t)); return; } @@ -89,6 +92,15 @@ public static void run(Class quarkusApplication, B } + private static void handleReflectiveInvocationIssue(BiConsumer exitHandler, Throwable t) { + if (exitHandler != null) { + exitHandler.accept(1, t); + } else { + Logger.getLogger(Quarkus.class).error("Error running Quarkus", t); + ApplicationLifecycleManager.getDefaultExitCodeHandler().accept(1, t); + } + } + private static void launchFromIDE(Class quarkusApplication, String... args) { //some trickery, get the class that has invoked us, and use this to figure out the //classes root