alibaba/nacos · error · NestedIoException
Invalid URI [{url}]
Error message
Invalid URI [{url}] What it means
Thrown by AbstractResource.getUri() when getUrl() succeeds but ResourceUtils.toUri(url) raises URISyntaxException — the URL string is not a valid URI. Wrapped as NestedIoException. It indicates a malformed URL (illegal characters, bad encoding) rather than a missing resource.
Source
Thrown at common/src/main/java/com/alibaba/nacos/common/packagescan/resource/AbstractResource.java:124
* This implementation throws a FileNotFoundException, assuming
* that the resource cannot be resolved to a URL.
*/
@Override
public URL getUrl() throws IOException {
throw new FileNotFoundException(getDescription() + " cannot be resolved to URL");
}
/**
* This implementation builds a URI based on the URL returned
* by {@link #getUrl()}.
*/
@Override
public URI getUri() throws IOException {
URL url = getUrl();
try {
return ResourceUtils.toUri(url);
} catch (URISyntaxException ex) {
throw new NestedIoException("Invalid URI [" + url + "]", ex);
}
}
/**
* This implementation throws a FileNotFoundException, assuming
* that the resource cannot be resolved to an absolute file path.
*/
@Override
public File getFile() throws IOException {
throw new FileNotFoundException(getDescription() + " cannot be resolved to absolute file path");
}
/**
* This implementation returns {@link Channels#newChannel(InputStream)}
* with the result of {@link #getInputStream()}.
* This is the same as in {@link Resource}'s corresponding default method
* but mirrored here for efficient JVM-level dispatching in a class hierarchy.
*/View on GitHub (pinned to 9b989acdf1)
Solutions
- URL-encode path components when constructing the resource URL so getUri() parses cleanly.
- Catch NestedIoException/URISyntaxException and fall back to using the URL directly instead of URI.
- Sanitize the path (remove/encode spaces) before creating the resource.
- Use ResourceUtils.toUri after pre-encoding with URLEncoder on the relevant segment.
Example fix
// before
Resource res = new UrlResource("file:/C:/Program Files/app/conf.json");
URI u = res.getUri(); // NestedIoException: Invalid URI (space)
// after
String encoded = "file:///C:/Program%20Files/app/conf.json";
Resource res = new UrlResource(encoded);
URI u = res.getUri(); Defensive patterns
Strategy: validation
Validate before calling
// pre-encode path segments containing illegal URI characters
String safe = rawPath.replace(" ", "%20");
Resource res = new UrlResource(safe);
URI u = res.getUri(); Type guard
boolean isParsableUri(URL url) {
try { url.toURI(); return true; }
catch (URISyntaxException e) { return false; }
} Try / catch
try {
URI u = resource.getUri();
} catch (NestedIoException e) {
if (e.getCause() instanceof URISyntaxException) {
log.error("Malformed URL — encode path components: {}", e.getMessage());
}
throw e;
} Prevention
- URL-encode spaces and non-ASCII in file paths, especially on Windows.
- Validate URLs with new URI(spec) before constructing resources.
- Catch NestedIoException and fall back to the URL when a URI is unavailable.
When it happens
Trigger: Calling resource.getUri() on a resource whose URL contains characters illegal in a URI (spaces, unencoded non-ASCII, stray characters) so java.net.URI rejects it.
Common situations: File paths with spaces or non-ASCII on Windows; custom URL schemes with unencoded components; a classpath URL containing characters that survive as URL but fail URI parsing; a misconstructed resource path.
Related errors
- {getDescription()} cannot be resolved to URL
- {getDescription()} cannot be resolved to URL because it does
- {getDescription()} cannot be resolved in the file system for
- {getDescription()} cannot be resolved in the file system for
- {getDescription()} cannot be resolved to absolute file path
AI-assisted analysis of alibaba/nacos@9b989acdf1 (2026-08-14).
Data as JSON: /api/errors/5bc1a19e1de6b62e.
Report an issue: GitHub.