{"record":{"id":"b7ea66f3f83a6577","repo":"alibaba/nacos","slug":"invalid-fieldname-value","errorCode":null,"errorMessage":"Invalid {fieldName}: {value}","messagePattern":"Invalid (.+?): (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"api/src/main/java/com/alibaba/nacos/api/ai/utils/AgentModelValidator.java","lineNumber":625,"sourceCode":"            expected = RuntimeEndpointState.AVAILABLE;\n        }\n        if (item.getState() != expected) {\n            throw new IllegalArgumentException(\n                \"Runtime Endpoint state must be \" + expected.name());\n        }\n    }\n    \n    private static void validateEndpoint(Endpoint endpoint) {\n        requireNonNull(endpoint, \"Endpoint\");\n        EndpointCanonicalizer.canonicalize(endpoint);\n        if (endpoint.getHealthy() != null) {\n            throw new IllegalArgumentException(\"Management or declared Endpoint forbids healthy\");\n        }\n    }\n    \n    private static void validateAbsoluteUri(String value, String fieldName) {\n        if (value.isEmpty() || codePointLength(value) > MAX_URI_LENGTH) {\n            throw new IllegalArgumentException(\"Invalid \" + fieldName + \": \" + value);\n        }\n        try {\n            URI uri = new URI(value);\n            if (!uri.isAbsolute()) {\n                throw new IllegalArgumentException(\"Invalid \" + fieldName + \": \" + value);\n            }\n        } catch (URISyntaxException e) {\n            throw new IllegalArgumentException(\"Invalid \" + fieldName + \": \" + value, e);\n        }\n    }\n    \n    private static void validateRequiredLength(String value, int maximum, String fieldName) {\n        if (value == null || value.isEmpty() || codePointLength(value) > maximum) {\n            throw new IllegalArgumentException(\"Invalid \" + fieldName + \": \" + value);\n        }\n    }\n    \n    private static void validateOptionalLength(String value, int maximum, String fieldName) {","sourceCodeStart":607,"sourceCodeEnd":643,"githubUrl":"https://github.com/alibaba/nacos/blob/9b989acdf181d00898f2e8839257bb2b2a3cefe3/api/src/main/java/com/alibaba/nacos/api/ai/utils/AgentModelValidator.java#L607-L643","documentation":"Thrown by validateAbsoluteUri when a required absolute URI field is empty or longer than MAX_URI_LENGTH (2048 code points). This is the first of three guards inside validateAbsoluteUri; it checks the raw string before attempting URI parsing, so it catches empty strings and over-long values cheaply. The fieldName identifies which Agent field failed (iconUrl or provider.url).","triggerScenarios":"An Agent publish/update where iconUrl (Agent.getIconUrl()) or provider.url (AgentProvider.getUrl()) is an empty string or a string whose codePointCount exceeds 2048. Reached via validateAgentFields -> validateAbsoluteUri. Note iconUrl is optional overall but, when present and non-null, is validated; an empty (not null) iconUrl fails here.","commonSituations":"Submitting iconUrl as \"\" instead of null/omitted; pasting a data: URI or a very long signed URL for an icon; a provider URL with many query parameters exceeding the limit; truncation bugs that produce empty strings.","solutions":["For optional iconUrl/provider.url, omit the field (send null) rather than an empty string.","Shorten the URI to <= 2048 code points; for icons, host the image and use a short https URL instead of an inline data: URI.","If the URL is genuinely long (signed/CDN), store a stable short redirector URL instead.","Trim whitespace and confirm codePointCount (not byte length) is within 2048."],"exampleFix":"// before\nagent.setIconUrl(\"\"); // empty -> rejected\nprovider.setUrl(longSignedDataUri); // > 2048 code points -> rejected\n// after\nagent.setIconUrl(null); // omit when unused\nprovider.setUrl(\"https://cdn.example.com/icon.png\");","handlingStrategy":"validation","validationCode":"static void checkAbsUri(String v, String field) {\n    if (v != null && (v.isEmpty() || v.codePointCount(0, v.length()) > 2048)) {\n        throw new IllegalArgumentException(\"Invalid \" + field + \": \" + v);\n    }\n}\ncheckAbsUri(agent.getIconUrl(), \"iconUrl\");\nif (agent.getProvider() != null) checkAbsUri(agent.getProvider().getUrl(), \"provider.url\");","typeGuard":"static boolean uriLengthOk(String v) {\n    return v == null || (!v.isEmpty() && v.codePointCount(0, v.length()) <= 2048);\n}","tryCatchPattern":"try {\n    AgentModelValidator.validateAgent(agent);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().startsWith(\"Invalid iconUrl\") || e.getMessage().startsWith(\"Invalid provider.url\")) {\n        // shorten or null-out the offending URI\n    } else throw e;\n}","preventionTips":["Send null (omit) for unused optional URIs, not empty strings.","Host icons externally and use short https URLs instead of inline data: URIs.","Measure code points, not bytes, when enforcing 2048."],"tags":["ai-agent","validation","uri","length-limit"],"backgroundTag":null,"analyzedSha":"9b989acdf181d00898f2e8839257bb2b2a3cefe3","analyzedAt":"2026-08-14T07:17:31.569Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}