{"record":{"id":"d941ca01a55affef","repo":"elastic/elasticsearch","slug":"failed-to-build-classpath-urls-d941ca","errorCode":null,"errorMessage":"Failed to build classpath URLs.","messagePattern":"Failed to build classpath URLs\\.","errorType":"validation","errorClass":"InvalidUserDataException","httpStatus":null,"severity":"error","filePath":"build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/precommit/CheckForbiddenApisTask.java","lineNumber":574,"sourceCode":"        }\n\n        private URLClassLoader createClassLoader(FileCollection classpath, FileCollection classesDirs) {\n            if (classesDirs == null || classpath == null) {\n                throw new InvalidUserDataException(\"Missing 'classesDirs' or 'classpath' property.\");\n            }\n\n            final Set<File> cpElements = new LinkedHashSet<>();\n            cpElements.addAll(classpath.getFiles());\n            cpElements.addAll(classesDirs.getFiles());\n            final URL[] urls = new URL[cpElements.size()];\n            try {\n                int i = 0;\n                for (final File cpElement : cpElements) {\n                    urls[i++] = cpElement.toURI().toURL();\n                }\n                assert i == urls.length;\n            } catch (MalformedURLException mfue) {\n                throw new InvalidUserDataException(\"Failed to build classpath URLs.\", mfue);\n            }\n\n            RegularFileProperty foreignApiJarProp = getParameters().getForeignApiJar();\n            if (foreignApiJarProp.isPresent()) {\n                try {\n                    File jarFile = foreignApiJarProp.getAsFile().get();\n                    URL foreignJarUrl = jarFile.toURI().toURL();\n                    return new ForeignFirstClassLoader(foreignJarUrl, urls, ClassLoader.getSystemClassLoader());\n                } catch (MalformedURLException mfue) {\n                    throw new InvalidUserDataException(\"Failed to build foreign API JAR URL.\", mfue);\n                }\n            }\n            return URLClassLoader.newInstance(urls, ClassLoader.getSystemClassLoader());\n        }\n\n        /**\n         * A classloader that checks its own URLs before delegating to the parent for\n         * classes and resources under {@code java/lang/foreign/}. This allows a","sourceCodeStart":556,"sourceCodeEnd":592,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/precommit/CheckForbiddenApisTask.java#L556-L592","documentation":"Thrown while building the URL[] for the forbidden-apis classloader: a File in the merged classpath+classesDirs collection produced a MalformedURLException via toURI().toURL(). Mirrors [242] but on the forbidden-apis task's classloader construction.","triggerScenarios":"A classpath or classesDirs element whose File.toURI().toURL() fails — a synthetic, deleted, or non-file FileCollection entry.","commonSituations":"A compile classpath containing a resolved artifact that no longer exists on disk; a custom configuration with non-artifact entries; filesystem/encoding issues with the build directory path.","solutions":["Print the resolved files of both classpath and classesDirs and look for missing/odd entries.","Ensure inputs come from real configurations and source set outputs.","Run a clean build to regenerate class files.","Inspect the wrapped MalformedURLException for the failing path."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Pre-check every classpath/classesDirs file resolves to a URL\nfor (File f : concat(classpath.getFiles(), classesDirs.getFiles())) {\n    try { f.toURI().toURL(); } catch (MalformedURLException e) { throw new InvalidUserDataException(\"Bad entry: \" + f, e); }\n}","typeGuard":null,"tryCatchPattern":"try {\n    URL[] urls = buildUrls(classpath, classesDirs);\n} catch (InvalidUserDataException e) {\n    throw new GradleException(\"Classpath URL build failed; run clean build\", e);\n}","preventionTips":["Source classpaths from real configurations and source set outputs.","Run a clean build if entries vanish.","Avoid mutating build outputs during a build."],"tags":["gradle","forbidden-apis","precommit","classpath","url"],"backgroundTag":null,"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-12T12:31:55.035Z"}