{"record":{"id":"699eabe0e4b0b9f4","repo":"apache/maven","slug":"required-test-class-is-not-available-in-extensionc","errorCode":null,"errorMessage":"Required test class is not available in ExtensionContext","messagePattern":"Required test class is not available in ExtensionContext","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"impl/maven-testing/src/main/java/org/apache/maven/testing/di/MavenDIExtension.java","lineNumber":107,"sourceCode":"     */\n    protected static Optional<ExtensionContext> getContext() {\n        return Optional.ofNullable(EXTENSION_CONTEXT_THREAD_LOCAL.get());\n    }\n\n    /**\n     * Creates and configures the DI container for test execution.\n     * Performs component discovery and sets up basic bindings.\n     *\n     * @throws IllegalStateException if the ExtensionContext is null, the required test class is unavailable,\n     *         the required test instance is unavailable, or if container setup fails\n     */\n    protected Injector setupContainer(ExtensionContext context) {\n        if (context == null) {\n            throw new IllegalStateException(\"ExtensionContext must not be null\");\n        }\n        final Class<?> testClass = context.getRequiredTestClass();\n        if (testClass == null) {\n            throw new IllegalStateException(\"Required test class is not available in ExtensionContext\");\n        }\n        final Object testInstance = context.getRequiredTestInstance();\n        if (testInstance == null) {\n            throw new IllegalStateException(\"Required test instance is not available in ExtensionContext\");\n        }\n\n        try {\n            Injector injector = Injector.create();\n            injector.bindInstance(ExtensionContext.class, context);\n            injector.discover(testClass.getClassLoader());\n            injector.bindInstance(Injector.class, injector);\n            injector.bindInstance(testClass.asSubclass(Object.class), (Object) testInstance); // Safe generics handling\n            return injector;\n        } catch (final Exception e) {\n            throw new IllegalStateException(\n                    String.format(\n                            \"Failed to set up DI injector for test class '%s': %s\",\n                            testClass.getName(), e.getMessage()),","sourceCodeStart":89,"sourceCodeEnd":125,"githubUrl":"https://github.com/apache/maven/blob/e4093d4e120eac99d6bdce5ba67cace2f3085c97/impl/maven-testing/src/main/java/org/apache/maven/testing/di/MavenDIExtension.java#L89-L125","documentation":"Error \"Required test class is not available in ExtensionContext\" thrown in apache/maven.","triggerScenarios":"Thrown at impl/maven-testing/src/main/java/org/apache/maven/testing/di/MavenDIExtension.java:107 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"e4093d4e120eac99d6bdce5ba67cace2f3085c97","analyzedAt":"2026-08-21T22:58:24.034Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}