spring-projects/spring-boot · error · IllegalStateException

Invalid URL for

Error message

Invalid URL for {}

What it means

Thrown by AbstractDependencyFilterMojo.toURL when File.toURI().toURL() throws a MalformedURLException. This helper converts a File to a URL for classpath assembly. In practice File.toURI().toURL() almost never throws (URI.toURL only fails on non-absolute or non-URL-compatible URIs), so this is a defensive guard for pathological file paths. The IllegalStateException wraps the original MalformedURLException with the offending File.

Solutions

  1. Inspect the 'file' value in the message: if it is a relative path, ensure artifacts resolve to absolute paths.
  2. Check the local Maven repository (~/.m2/repository) for corrupted or oddly-named artifact paths and re-resolve with 'mvn dependency:purge-local-repository'.
  3. Verify no custom artifact factory or local-repository layout is producing non-URL-compatible paths.
  4. As a last resort, run 'mvn clean package -X' and inspect the artifact paths in the debug log.
Defensive patterns

Strategy: try-catch

Validate before calling

// Pre-validate that artifact files convert to URLs cleanly.
for (File f : directories) {
    if (!f.isAbsolute()) f = f.getAbsoluteFile();
    try {
        f.toURI().toURL();
    } catch (MalformedURLException ex) {
        throw new IllegalArgumentException("Cannot convert to URL: " + f, ex);
    }
}

Try / catch

// Catch IllegalStateException and surface the offending file.
try {
    mojo.toURL(artifactFile);
} catch (IllegalStateException ex) {
    // 'file' value is in the message — re-resolve the artifact
    artifact = mavenResolver.resolveArtifact(artifactCoords);
}

Prevention

When it happens

Trigger: Passing a File to toURL whose path, when converted to a URI, yields a non-absolute or otherwise URL-incompatible URI. This is invoked by getClassPath and getDependencyURLs when building the runtime/compile classpath for filtering in the Maven plugin.

Common situations: A dependency artifact resolved to a path with characters that break URI-to-URL conversion (extremely rare since toURI normalizes). A File object constructed from a relative path that does not normalize to absolute. A repository path containing characters outside the legal URL set. Custom ArtifactResolver or local repository layouts producing odd paths. Essentially never fires in standard Maven usage.

Related errors


AI-assisted analysis of spring-projects/spring-boot@270dfe353f (2026-08-11). Data as JSON: /api/errors/d64326f4fe5ebb8b. Report an issue: GitHub.

Appendix: source

Thrown at build-plugin/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/AbstractDependencyFilterMojo.java:142

	protected final Set<Artifact> filterDependencies(Set<Artifact> dependencies, ArtifactsFilter... additionalFilters)
			throws MojoExecutionException {
		try {
			Set<Artifact> filtered = new LinkedHashSet<>(dependencies);
			filtered.retainAll(getFilters(additionalFilters).filter(dependencies));
			return filtered;
		}
		catch (ArtifactFilterException ex) {
			throw new MojoExecutionException(ex.getMessage(), ex);
		}
	}

	protected URL toURL(File file) {
		try {
			return file.toURI().toURL();
		}
		catch (MalformedURLException ex) {
			throw new IllegalStateException("Invalid URL for " + file, ex);
		}
	}

	/**
	 * Return artifact filters configured for this MOJO.
	 * @param additionalFilters optional additional filters to apply
	 * @return the filters
	 */
	private FilterArtifacts getFilters(ArtifactsFilter... additionalFilters) {
		FilterArtifacts filters = new FilterArtifacts();
		for (ArtifactsFilter additionalFilter : additionalFilters) {
			filters.addFilter(additionalFilter);
		}
		filters.addFilter(new MatchingGroupIdFilter(cleanFilterConfig(this.excludeGroupIds)));
		if (this.includes != null && !this.includes.isEmpty()) {
			filters.addFilter(new IncludeFilter(this.includes));
		}
		if (this.excludes != null && !this.excludes.isEmpty()) {

View on GitHub (pinned to 270dfe353f)