{"record":{"id":"6018455aef2a1a50","repo":"apache/maven","slug":"error-creating-toolchain-of-type","errorCode":null,"errorMessage":"Error creating toolchain of type {}","messagePattern":"Error creating toolchain of type (.+?)","errorType":"exception","errorClass":"ToolchainManagerException","httpStatus":null,"severity":"error","filePath":"impl/maven-impl/src/main/java/org/apache/maven/impl/DefaultToolchainManager.java","lineNumber":108,"sourceCode":"        Map<String, Object> context = retrieveContext(session);\n        ToolchainModel model = (ToolchainModel) context.get(\"toolchain-\" + type);\n        return Optional.ofNullable(model).flatMap(this::createToolchain);\n    }\n\n    @Override\n    public void storeToolchainToBuildContext(@Nonnull Session session, @Nonnull Toolchain toolchain) {\n        Map<String, Object> context = retrieveContext(session);\n        context.put(\"toolchain-\" + toolchain.getType(), toolchain.getModel());\n    }\n\n    private Optional<Toolchain> createToolchain(ToolchainModel model) {\n        String type = Objects.requireNonNull(model.getType(), \"model.getType()\");\n        ToolchainFactory factory = factories.get(type);\n        if (factory != null) {\n            try {\n                return Optional.of(factory.createToolchain(model));\n            } catch (ToolchainFactoryException e) {\n                throw new ToolchainManagerException(\"Error creating toolchain of type \" + type, e);\n            }\n        } else {\n            logger.error(\"Missing toolchain factory for type: \" + type + \". Possibly caused by misconfigured project.\");\n        }\n        return Optional.empty();\n    }\n\n    private static final SessionData.Key<ConcurrentHashMap<Project, ConcurrentHashMap<String, Object>>>\n            TOOLCHAIN_CONTEXT_KEY = (SessionData.Key) SessionData.key(ConcurrentHashMap.class, \"toolchain-context\");\n\n    protected Map<String, Object> retrieveContext(Session session) {\n        Optional<Project> current = session.getService(Lookup.class).lookupOptional(Project.class);\n        if (current.isPresent()) {\n            var map = session.getData().computeIfAbsent(TOOLCHAIN_CONTEXT_KEY, ConcurrentHashMap::new);\n            return map.computeIfAbsent(current.get(), p -> new ConcurrentHashMap<>());\n        }\n        return new HashMap<>();\n    }","sourceCodeStart":90,"sourceCodeEnd":126,"githubUrl":"https://github.com/apache/maven/blob/e4093d4e120eac99d6bdce5ba67cace2f3085c97/impl/maven-impl/src/main/java/org/apache/maven/impl/DefaultToolchainManager.java#L90-L126","documentation":"DefaultToolchainManager looks up a ToolchainFactory by the <type> declared in each toolchains.xml entry and delegates creation. If that factory throws ToolchainFactoryException (invalid toolchain definition), the manager wraps it as ToolchainManagerException naming the type. A missing factory for a type is only logged as an error, not thrown, so this exception always means a factory rejected the entry.","triggerScenarios":"A toolchains.xml entry whose type maps to a factory that fails: jdk toolchain with a missing or invalid home, or a custom toolchain provider validating properties and throwing ToolchainFactoryException.","commonSituations":"CI images where paths in toolchains.xml do not exist; typos or omissions in required toolchain properties; custom toolchain providers with stricter validation than Maven's built-ins.","solutions":["Read the cause - the ToolchainFactoryException carries the specific reason","Fix the toolchains.xml entry for the named type: paths must exist and required properties must be set","Comment out toolchain entries one by one to isolate which entry fails","For custom providers, run their validation directly on the model during development"],"exampleFix":"<!-- before -->\n<toolchain>\n  <type>jdk</type>\n  <provides><version>17</version></provides>\n  <configuration>\n    <jdkHome>/opt/jdks/17</jdkHome> <!-- path missing on this machine -->\n  </configuration>\n</toolchain>\n\n<!-- after -->\n<toolchain>\n  <type>jdk</type>\n  <provides><version>17</version></provides>\n  <configuration>\n    <jdkHome>/opt/jdk-17.0.9</jdkHome> <!-- existing path -->\n  </configuration>\n</toolchain>","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    Optional<Toolchain> tc = toolchainManager.getToolchainFromBuildContext(\"jdk\", session);\n} catch (ToolchainManagerException e) {\n    String type = /* from message */ e.getMessage();\n    log.error(\"toolchain of type failed: {}\", e.getMessage(), e.getCause());\n    // fix the toolchains.xml entry named in the cause\n}","preventionTips":["Validate that paths referenced in toolchains.xml exist on the machine before builds","Keep toolchains.xml under CI-managed templates instead of hand edits","For custom toolchain providers, run factory validation during development"],"tags":["maven","toolchains","configuration","factory"],"backgroundTag":"invalid-toolchain-configuration","analyzedSha":"e4093d4e120eac99d6bdce5ba67cace2f3085c97","analyzedAt":"2026-08-21T22:58:24.034Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}