{"record":{"id":"2f1725db9ab1f250","repo":"quarkusio/quarkus","slug":"unable-to-handle-class-applicationclass","errorCode":null,"errorMessage":"Unable to handle class: ${applicationClass}","messagePattern":"Unable to handle class: (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"extensions/resteasy-classic/resteasy-server-common/deployment/src/main/java/io/quarkus/resteasy/server/common/deployment/ResteasyServerCommonProcessor.java","lineNumber":1115,"sourceCode":"        String applicationClass = jakartaRestApplicationClass.name().toString();\n        try {\n            Class<?> appClass = Thread.currentThread().getContextClassLoader().loadClass(applicationClass);\n            application = (Application) appClass.getConstructor().newInstance();\n            Set<Class<?>> classes = application.getClasses();\n            if (!classes.isEmpty()) {\n                for (Class<?> klass : classes) {\n                    allowedClasses.add(klass.getName());\n                }\n            }\n            classes = application.getSingletons().stream().map(Object::getClass).collect(Collectors.toSet());\n            if (!classes.isEmpty()) {\n                for (Class<?> klass : classes) {\n                    allowedClasses.add(klass.getName());\n                }\n            }\n        } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | NoSuchMethodException\n                | InvocationTargetException e) {\n            throw new RuntimeException(\"Unable to handle class: \" + applicationClass, e);\n        }\n        return allowedClasses;\n    }\n}\n","sourceCodeStart":1097,"sourceCodeEnd":1120,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/extensions/resteasy-classic/resteasy-server-common/deployment/src/main/java/io/quarkus/resteasy/server/common/deployment/ResteasyServerCommonProcessor.java#L1097-L1120","documentation":"getAllowedClasses in ResteasyServerCommonProcessor loads the user's Application class via reflection (Class.forName, newInstance or getMethod calls) at build time to invoke getClasses()/getSingletons(). Any failure while loading, instantiating, or invoking it — ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, or InvocationTargetException — is wrapped in this RuntimeException naming the offending class.","triggerScenarios":"Application class that: cannot be loaded (missing dependency of a referenced type), has no accessible no-arg constructor, throws an exception inside its constructor or getClasses()/getSingletons(), or references classes not visible to the deployment classloader.","commonSituations":"Application's constructor/getClasses throws NPE due to uninitialized static state; Application references a class from a library not on the deployment classpath; a private or missing no-arg constructor.","solutions":["Read the wrapped cause (the RuntimeException's getCause()) to see the underlying exception thrown while loading/invoking the Application class.","Ensure the Application class has a public no-arg constructor that performs no side-effecting/CDI-dependent initialization.","Make every type referenced in getClasses()/getSingletons() available on the classpath and keep the methods side-effect free.","As a workaround, drop getClasses()/getSingletons() and let Quarkus discover @Path/@Provider classes automatically."],"exampleFix":"// before\npublic class MyApp extends Application {\n    private static final Set<Class<?>> CLASSES = buildFromDb(); // throws at build time\n    @Override public Set<Class<?>> getClasses() { return CLASSES; }\n}\n\n// after\npublic class MyApp extends Application {\n    @Override public Set<Class<?>> getClasses() { return Set.of(MyResource.class); }\n}","handlingStrategy":"try-catch","validationCode":"static void assertApplicationInstantiable(String appClassName) {\n    try {\n        Class<?> c = Class.forName(appClassName);\n        c.getDeclaredConstructor().newInstance();\n    } catch (ReflectiveOperationException e) {\n        throw new IllegalStateException(\"Application class cannot be loaded/instantiated at build time: \" + appClassName, e);\n    }\n}","typeGuard":"static boolean isBuildTimeInstantiable(Class<?> c) {\n    try { c.getDeclaredConstructor().newInstance(); return true; }\n    catch (ReflectiveOperationException | RuntimeException e) { return false; }\n}","tryCatchPattern":"// Thrown during Quarkus augmentation; inspect the wrapped cause to diagnose:\ntry {\n    Quarkus.bootstrap(...); // or run quarkusDev\n} catch (RuntimeException e) {\n    if (e.getMessage() != null && e.getMessage().startsWith(\"Unable to handle class:\")) {\n        log.error(\"Root cause while loading Application class:\", e.getCause());\n    }\n}","preventionTips":["Keep the Application class constructor side-effect free with no external dependencies","Ensure all classes returned by getClasses()/getSingletons() are on the deployment classpath","Test Application instantiation in a plain JVM unit test before building the app","Prefer annotation-based discovery over getClasses() in Quarkus"],"tags":["jaxrs","deployment","reflection","resteasy","build-time"],"backgroundTag":"class-instantiation-failed","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}