{"record":{"id":"83cd5aa9e133edf8","repo":"apache/maven","slug":"error-building-toolchains","errorCode":null,"errorMessage":"Error building toolchains","messagePattern":"Error building toolchains","errorType":"exception","errorClass":"ToolchainsBuilderException","httpStatus":null,"severity":"error","filePath":"impl/maven-impl/src/main/java/org/apache/maven/impl/DefaultToolchainsBuilder.java","lineNumber":78,"sourceCode":"    public DefaultToolchainsBuilder(Interpolator interpolator, ToolchainsXmlFactory toolchainsXmlFactory) {\n        this.interpolator = interpolator;\n        this.toolchainsXmlFactory = toolchainsXmlFactory;\n    }\n\n    @Override\n    public ToolchainsBuilderResult build(ToolchainsBuilderRequest request) throws ToolchainsBuilderException {\n        ProblemCollector<BuilderProblem> problems = ProblemCollector.create(request.getSession());\n\n        Source installationSource = request.getInstallationToolchainsSource().orElse(null);\n        PersistedToolchains installation = readToolchains(installationSource, request, problems);\n\n        Source userSource = request.getUserToolchainsSource().orElse(null);\n        PersistedToolchains user = readToolchains(userSource, request, problems);\n\n        PersistedToolchains effective = toolchainsMerger.merge(user, installation, false, null);\n\n        if (problems.hasErrorProblems()) {\n            throw new ToolchainsBuilderException(\"Error building toolchains\", problems);\n        }\n\n        return new DefaultToolchainsBuilderResult(request, effective, problems);\n    }\n\n    private PersistedToolchains readToolchains(\n            Source toolchainsSource, ToolchainsBuilderRequest request, ProblemCollector<BuilderProblem> problems) {\n        if (toolchainsSource == null) {\n            return PersistedToolchains.newInstance();\n        }\n\n        PersistedToolchains toolchains;\n\n        try {\n            try {\n                InputStream is = toolchainsSource.openStream();\n                if (is == null) {\n                    return PersistedToolchains.newInstance();","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/apache/maven/blob/e4093d4e120eac99d6bdce5ba67cace2f3085c97/impl/maven-impl/src/main/java/org/apache/maven/impl/DefaultToolchainsBuilder.java#L60-L96","documentation":"Thrown by DefaultToolchainsBuilder.build when merging the installation-level and user-level toolchains.xml produces error-severity problems, for example parse failures in either file. The exception carries the ProblemCollector of BuilderProblem entries; iterating them yields the failing file and location.","triggerScenarios":"Malformed toolchains.xml in ~/.m2/toolchains.xml or in the installation-level file; toolchains sources that exist but cannot be read or parsed.","commonSituations":"Hand-edited toolchains.xml with XML errors; CI-managed toolchains files corrupted during provisioning; merge of user and installation files surfacing conflicting definitions.","solutions":["Catch ToolchainsBuilderException and iterate the attached problem collector for file and line details","Fix the reported XML in the named toolchains file","Temporarily rename the toolchains files to confirm which source produces the error"],"exampleFix":"// before\nToolchainsBuilderResult result = toolchainsBuilder.build(request);\n\n// after\ntry {\n    ToolchainsBuilderResult result = toolchainsBuilder.build(request);\n} catch (ToolchainsBuilderException e) {\n    e.getProblemCollector().getProblems()\n        .forEach(p -> log.error(\"{}: {}\", p.getLocation(), p.getMessage()));\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    ToolchainsBuilderResult result = toolchainsBuilder.build(request);\n} catch (ToolchainsBuilderException e) {\n    e.getProblemCollector().getProblems()\n        .forEach(p -> log.error(\"{}: {}\", p.getLocation(), p.getMessage()));\n    // fall back to no toolchains rather than abort the build, if acceptable\n}","preventionTips":["Lint toolchains.xml files during CI provisioning","Isolate user versus installation toolchains files when diagnosing merge errors"],"tags":["maven","toolchains","builder","configuration"],"backgroundTag":"invalid-config-file","analyzedSha":"e4093d4e120eac99d6bdce5ba67cace2f3085c97","analyzedAt":"2026-08-21T22:58:24.034Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}