{"record":{"id":"ede8923e47581fef","repo":"quarkusio/quarkus","slug":"failed-to-redefine-module-modulename","errorCode":null,"errorMessage":"Failed to redefine module ${moduleName}","messagePattern":"Failed to redefine module (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"core/deployment/src/main/java/io/quarkus/deployment/jvm/AgentBasedModulesReconfigurer.java","lineNumber":113,"sourceCode":"        if (logger.isDebugEnabled()) {\n            openInstructions.forEach(\n                    (pkg, modules) -> logger.debugf(\"Opening package %s of %s to modules %s\", pkg, sourceModule, modules));\n        }\n        try {\n            // We are redefining the target module, adding a new \"open\"\n            // rule for it.\n            //This method is additive: we don't need to read previous reads and exports\n            //to avoid losing them.\n            instrumentation.redefineModule(\n                    sourceModule, // The module to change\n                    Set.of(), // Extra reads\n                    Map.of(), // Extra exports\n                    openInstructions, // The relevant one\n                    Set.of(), // Extra uses\n                    Map.of() // Extra provides\n            );\n        } catch (Exception e) {\n            throw new RuntimeException(\"Failed to redefine module \" + sourceModule.getName());\n        }\n    }\n\n    // A convenience container to keep our logic above more readable\n    private static class PerModuleOpenInstructions {\n        private final Map<String, Set<Module>> modulesToOpenToByPackage = new HashMap<>();\n\n        public void addOpens(final String packageName, final Module openingModule) {\n            final Set<Module> modulesToOpenTo = modulesToOpenToByPackage.computeIfAbsent(packageName, k -> new HashSet<>());\n            modulesToOpenTo.add(openingModule);\n        }\n    }\n\n    /**\n     * This isn't going to transform any class, but we leverage the existing agent\n     * and register as a callback to provide useful diagnostics: we can detect new\n     * unnamed modules being created and log them.\n     * Obviously this has a cost, so register this only when the matching log level is enabled.","sourceCodeStart":95,"sourceCodeEnd":131,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/core/deployment/src/main/java/io/quarkus/deployment/jvm/AgentBasedModulesReconfigurer.java#L95-L131","documentation":"AgentBasedModulesReconfigurer uses the JVM's Agent-based Module.redefineModule API to open JPMS packages so Quarkus deployment code can access them. If redefining a source module throws for any reason, it is wrapped as this RuntimeException. It means the build could not relax module boundaries for the named module.","triggerScenarios":"During openJavaModules(), Module.redefineModule is invoked with computed open instructions for a module and the JVM rejects the call (module is not resolvable/already closed, invalid package name, security manager denial, or any other Exception from redefineModule).","commonSituations":"Unusual JDK builds (early access, hardened images) that restrict module redefinition; running with a SecurityManager or restrictive agent policies; packages computed from classpath scanning that do not exist in the target module; mismatched JDK versions where expected packages were removed.","solutions":["Run the build on a current, standard JDK LTS (17/21) from a mainstream vendor","Add explicit --add-opens flags on the build JVM for the packages the error mentions, avoiding the need for redefinition","Verify the package names exist in the named module (jar --describe-module or java --list-modules)","Remove SecurityManager/agent restrictions that could reject module redefinition"],"exampleFix":"// before\n./mvnw install   # custom JDK build rejects redefineModule\n// after\nexport JAVA_HOME=$(/usr/libexec/java_home -v 21)\n./mvnw install -DargLine=\"--add-opens java.base/java.lang=ALL-UNNAMED\"","handlingStrategy":"try-catch","validationCode":"// Verify the package exists in the module before attempting redefinition\nModule m = sourceModule;\nString pkg = packageName;\nif (m.getNamed() && !m.isExported(pkg) && m.getPackages() != null && !Set.of(m.getPackages()).contains(pkg)) {\n    throw new IllegalArgumentException(\"Package \" + pkg + \" not defined by module \" + m.getName());\n}","typeGuard":null,"tryCatchPattern":"try {\n    // deployment proceeds; AgentBasedModulesReconfigurer runs internally\n} catch (RuntimeException e) {\n    if (e.getMessage() != null && e.getMessage().startsWith(\"Failed to redefine module\")) {\n        log.errorf(e, \"Module redefinition failed for %s - consider explicit --add-opens\", e.getMessage());\n    }\n    throw e;\n}","preventionTips":["Use a standard, current LTS JDK from a mainstream vendor for builds","Add explicit --add-opens flags instead of relying on agent-based redefinition","Confirm packages with java --describe-module before scanning-based opens","Remove SecurityManager or restrictive agent configurations from the build JVM"],"tags":["quarkus","jpms","modules","jdk"],"backgroundTag":"jpms-module-access-denied","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"}