{"record":{"id":"312b5a6ee4d54a53","repo":"elastic/elasticsearch","slug":"failed-to-build-classpath-urls","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/packer/CacheCacheableTestFixtures.java","lineNumber":127,"sourceCode":"            }\n        }\n\n        private URLClassLoader createClassLoader(FileCollection classpath) {\n            if (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            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            return URLClassLoader.newInstance(urls, ClassLoader.getSystemClassLoader());\n        }\n\n    }\n}\n","sourceCodeStart":109,"sourceCodeEnd":135,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/packer/CacheCacheableTestFixtures.java#L109-L135","documentation":"Thrown while building a URL[] from a FileCollection for the fixtures classloader: one of the files produced a MalformedURLException from File.toURI().toURL(). toURI().toURL() almost never fails for real files, so this is a defensive guard for the rare case where the file path cannot be expressed as a valid URL.","triggerScenarios":"A classpath element whose File.toURI() returns a non-file/invalid URI that toURL() then rejects; typically a synthetic/placeholder file collection entry rather than a real artifact on disk.","commonSituations":"A custom FileCollection built from string-backed providers instead of real files; an artifact-resolved file that was deleted between configuration and execution; exotic paths with characters that break URI handling on some JVMs.","solutions":["Inspect the resolved classpath files (print files of the FileCollection) and look for null/non-file entries.","Ensure the classpath is derived from real resolved configurations (configurations.runtimeClasspath) rather than ad-hoc providers.","If a path is genuinely problematic, normalise/copy the artifact to a path with standard characters before building the URL.","Check the wrapped MalformedURLException in the stack trace to see exactly which path failed."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Pre-validate that every classpath file produces a usable URL\nfor (File f : classpath.getFiles()) {\n    try { f.toURI().toURL(); }\n    catch (MalformedURLException e) { throw new InvalidUserDataException(\"Bad classpath entry: \" + f, e); }\n}","typeGuard":null,"tryCatchPattern":"try {\n    URL[] urls = buildUrls(classpath);\n} catch (InvalidUserDataException e) {\n    // surface the failing path from the wrapped MalformedURLException\n    throw new GradleException(\"Classpath URL build failed; check resolved artifacts exist\", e);\n}","preventionTips":["Derive classpaths from real resolved Gradle configurations, not string-built providers.","Run a clean build when classpath entries go missing.","Log the resolved file list at --info when debugging."],"tags":["gradle","classpath","url","build-config","io"],"backgroundTag":null,"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-12T12:31:55.035Z"}