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() raises MalformedURLException, wrapped as IllegalStateException. toURL is used while building the classpath/dependency URLs for filtering mojos. In practice File.toURI() almost never yields a malformed URL, so this typically signals an exotic filesystem path or a degenerate File value.

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 5b2dbdbb8b)

Solutions

  1. Inspect the file value named in the message and confirm the artifact resolved to a real path.
  2. Run mvn dependency:tree / dependency:resolve to ensure all artifacts resolve to valid files.
  3. Clear the local Maven repo for the offending artifact and re-resolve.
  4. If a custom/resolved File is involved, ensure it represents an absolute, well-formed path.

Example fix

// shell: re-resolve a suspect artifact
//   rm -rf ~/.m2/repository/<group-path>/<artifact>
//   mvn dependency:resolve
Defensive patterns

Strategy: try-catch

Validate before calling

// Validate that all resolved artifacts map to readable, well-formed files
project.artifacts.forEach { art ->
    val f = art.file
    require(f != null && f.isAbsolute && f.canRead()) {
        "Artifact ${art} resolved to invalid file ${f}"
    }
    // toURI must not throw
    try { f.toURI().toURL() } catch (e: java.net.MalformedURLException) {
        throw IllegalArgumentException("Artifact ${art} has invalid URL form", e)
    }
}

Try / catch

try {
    // mojo goal that resolves dependencies
} catch (ex: IllegalStateException) {
    if (ex.message?.startsWith("Invalid URL for ") == true) {
        project.logger.error("An artifact resolved to an invalid file path; re-resolve dependencies.")
    }
    throw ex
}

Prevention

When it happens

Trigger: getDependencyURLs()/getClassPath() iterates project artifacts or directories and calls toURL(artifact.getFile()); if file.toURI().toURL() throws MalformedURLException, line 142 raises IllegalStateException("Invalid URL for " + file).

Common situations: An artifact whose resolved File is null-ish/unusual (rare); a path containing characters that the URI converter rejects on some JVMs; a custom artifact resolver returning a non-standard File; filesystem-specific oddities.

Related errors


AI-assisted analysis of spring-projects/spring-boot@5b2dbdbb8b (2026-08-04). Data as JSON: /data/errors/d64326f4fe5ebb8b.json. Report an issue: GitHub.