alibaba/nacos · error · IllegalArgumentException
Invalid {}
Error message
Invalid {} What it means
validateOptionalAbsoluteUri() rejects an optional URI field (iconUrl or provider.url) that is non-null but empty, or whose Unicode code-point length exceeds MAX_URI_LENGTH (2048). It throws 'Invalid <fieldName>' before even attempting to parse the URI.
Source
Thrown at ai/src/main/java/com/alibaba/nacos/ai/service/agent/metadata/AgentResourceExtSerializer.java:229
private static void validateCatalog(AgentVersionCatalog catalog) {
AgentModelValidator.validateVersionCatalog(catalog);
List<AgentVersionCatalogEntry> versions = catalog.getOnlineVersions();
for (int i = 1; i < versions.size(); i++) {
String previous = versions.get(i - 1).getVersion();
String current = versions.get(i).getVersion();
if (AgentVersionComparator.compare(previous, current) <= 0) {
throw new IllegalArgumentException(
"Agent Version catalog must use descending Version order");
}
}
}
private static void validateOptionalAbsoluteUri(String value, String fieldName) {
if (value == null) {
return;
}
if (value.isEmpty() || value.codePointCount(0, value.length()) > MAX_URI_LENGTH) {
throw new IllegalArgumentException("Invalid " + fieldName);
}
try {
URI uri = new URI(value);
if (!uri.isAbsolute()) {
throw new IllegalArgumentException(fieldName + " must be an absolute URI");
}
} catch (URISyntaxException e) {
throw new IllegalArgumentException("Invalid " + fieldName, e);
}
}
private static void validateOptionalCodePointLength(String value, int maxLength,
String fieldName) {
if (value != null && value.codePointCount(0, value.length()) > maxLength) {
throw new IllegalArgumentException(fieldName + " exceeds " + maxLength
+ " Unicode code points");
}
}View on GitHub (pinned to 9b989acdf1)
Solutions
- Omit the field (set to null) when you have no URI, rather than passing an empty string.
- If the value is legitimately long, shorten it (use a redirect/short link) to stay under 2048 code points.
- Validate length with value.codePointCount(0, value.length()) <= 2048 before submitting.
Example fix
// before
ext.setIconUrl(""); // empty string triggers 'Invalid iconUrl'
// after
ext.setIconUrl(null); // omit when not set Defensive patterns
Strategy: validation
Validate before calling
static String normalizeOptionalUri(String v) {
if (v == null || v.isEmpty()) return null; // treat empty as absent
if (v.codePointCount(0, v.length()) > 2048) throw new IllegalArgumentException("uri too long");
return v;
}
ext.setIconUrl(normalizeOptionalUri(ext.getIconUrl()));
ext.setProviderUrl(normalizeOptionalUri(provider.getUrl())); Prevention
- Omit (set null) optional URI fields instead of passing empty strings.
- Keep URIs under 2048 code points; use short links for long values.
- Validate length with codePointCount, not length().
When it happens
Trigger: Setting iconUrl or provider.url to "" (empty string), or to a very long value (>2048 code points) via the agent create/update API.
Common situations: Form handling that submits an empty string instead of omitting the field; pasting a data: URI or a URL with a huge query string.
Related errors
- {} must be an absolute URI
- Online Agent Version must contain callInterfaces
- Agent Version namespaceId does not match request
- Agent Version agentName does not match request
- Agent Version status must be online
AI-assisted analysis of alibaba/nacos@9b989acdf1 (2026-08-14).
Data as JSON: /api/errors/cc516f91b65d31b9.
Report an issue: GitHub.