elastic/elasticsearch · error · InvalidUserDataException

Failed to build classpath URLs.

Error message

Failed to build classpath URLs.

What it means

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.

Source

Thrown at build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/precommit/CheckForbiddenApisTask.java:574

        }

        private URLClassLoader createClassLoader(FileCollection classpath, FileCollection classesDirs) {
            if (classesDirs == null || classpath == null) {
                throw new InvalidUserDataException("Missing 'classesDirs' or 'classpath' property.");
            }

            final Set<File> cpElements = new LinkedHashSet<>();
            cpElements.addAll(classpath.getFiles());
            cpElements.addAll(classesDirs.getFiles());
            final URL[] urls = new URL[cpElements.size()];
            try {
                int i = 0;
                for (final File cpElement : cpElements) {
                    urls[i++] = cpElement.toURI().toURL();
                }
                assert i == urls.length;
            } catch (MalformedURLException mfue) {
                throw new InvalidUserDataException("Failed to build classpath URLs.", mfue);
            }

            RegularFileProperty foreignApiJarProp = getParameters().getForeignApiJar();
            if (foreignApiJarProp.isPresent()) {
                try {
                    File jarFile = foreignApiJarProp.getAsFile().get();
                    URL foreignJarUrl = jarFile.toURI().toURL();
                    return new ForeignFirstClassLoader(foreignJarUrl, urls, ClassLoader.getSystemClassLoader());
                } catch (MalformedURLException mfue) {
                    throw new InvalidUserDataException("Failed to build foreign API JAR URL.", mfue);
                }
            }
            return URLClassLoader.newInstance(urls, ClassLoader.getSystemClassLoader());
        }

        /**
         * A classloader that checks its own URLs before delegating to the parent for
         * classes and resources under {@code java/lang/foreign/}. This allows a

View on GitHub (pinned to db6a809a66)

Solutions

  1. Print the resolved files of both classpath and classesDirs and look for missing/odd entries.
  2. Ensure inputs come from real configurations and source set outputs.
  3. Run a clean build to regenerate class files.
  4. Inspect the wrapped MalformedURLException for the failing path.
Defensive patterns

Strategy: validation

Validate before calling

// Pre-check every classpath/classesDirs file resolves to a URL
for (File f : concat(classpath.getFiles(), classesDirs.getFiles())) {
    try { f.toURI().toURL(); } catch (MalformedURLException e) { throw new InvalidUserDataException("Bad entry: " + f, e); }
}

Try / catch

try {
    URL[] urls = buildUrls(classpath, classesDirs);
} catch (InvalidUserDataException e) {
    throw new GradleException("Classpath URL build failed; run clean build", e);
}

Prevention

When it happens

Trigger: A classpath or classesDirs element whose File.toURI().toURL() fails — a synthetic, deleted, or non-file FileCollection entry.

Common situations: 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.

Related errors


AI-assisted analysis of elastic/elasticsearch@db6a809a66 (2026-08-12). Data as JSON: /api/errors/d941ca01a55affef. Report an issue: GitHub.