{"record":{"id":"116b7301cd05d503","repo":"alibaba/nacos","slug":"invalid-fieldname-exceeds-maximum","errorCode":null,"errorMessage":"Invalid {fieldName}: exceeds {maximum}","messagePattern":"Invalid (.+?): exceeds (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"api/src/main/java/com/alibaba/nacos/api/ai/utils/AgentModelValidator.java","lineNumber":645,"sourceCode":"        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) {\n        if (value != null && codePointLength(value) > maximum) {\n            throw new IllegalArgumentException(\"Invalid \" + fieldName + \": exceeds \" + maximum);\n        }\n    }\n    \n    private static void validateEpochMillis(Long value, String fieldName) {\n        if (value == null || value < 0) {\n            throw new IllegalArgumentException(fieldName + \" must be a non-negative integer\");\n        }\n    }\n    \n    private static int codePointLength(String value) {\n        return value.codePointCount(0, value.length());\n    }\n    \n    private static <T> T requireNonNull(T value, String fieldName) {\n        if (value == null) {\n            throw new IllegalArgumentException(fieldName + \" must not be null\");\n        }\n        return value;","sourceCodeStart":627,"sourceCodeEnd":663,"githubUrl":"https://github.com/alibaba/nacos/blob/9b989acdf181d00898f2e8839257bb2b2a3cefe3/api/src/main/java/com/alibaba/nacos/api/ai/utils/AgentModelValidator.java#L627-L663","documentation":"Thrown by validateOptionalLength when an optional string field, when present (non-null), exceeds its maximum length in code points. Unlike validateRequiredLength, null and empty are allowed; only over-length is rejected. Fields guarded: displayName (MAX_DISPLAY_NAME_LENGTH=128) and description (MAX_DESCRIPTION_LENGTH=2048).","triggerScenarios":"Agent publish/update via validateAgentFields with a displayName longer than 128 code points, or a description longer than 2048 code points. Null/empty values for these two are accepted.","commonSituations":"Pasting a long marketing display name; a description field populated from a README or multi-paragraph doc; emoji/CJK content where code points exceed the cap well before byte length would; UI not enforcing a maxlength on these inputs.","solutions":["Trim displayName to <= 128 code points and description to <= 2048 code points.","Move long-form content out of description (e.g. link to an external doc) and keep description as a short summary.","Enforce maxlength in the submitting UI using code-point counting, not character/byte length.","If you must keep a long description, host it externally and reference it from an extension."],"exampleFix":"// before\nagent.setDisplayName(veryLongMarketingTitle); // > 128 code points -> rejected\nagent.setDescription(fullReadme);             // > 2048 -> rejected\n// after\nagent.setDisplayName(veryLongMarketingTitle.substring(0, 128));\nagent.setDescription(shortSummary); // <= 2048 code points","handlingStrategy":"validation","validationCode":"static void optionalLen(String v, int max, String field) {\n    if (v != null && v.codePointCount(0, v.length()) > max) {\n        throw new IllegalArgumentException(\"Invalid \" + field + \": exceeds \" + max);\n    }\n}\noptionalLen(agent.getDisplayName(), 128, \"displayName\");\noptionalLen(agent.getDescription(), 2048, \"description\");","typeGuard":"static boolean optionalLengthOk(String v, int max) {\n    return v == null || v.codePointCount(0, v.length()) <= max;\n}","tryCatchPattern":"try {\n    AgentModelValidator.validateAgent(agent);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().contains(\"exceeds 128\") || e.getMessage().contains(\"exceeds 2048\")) {\n        // trim displayName/description and retry\n    } else throw e;\n}","preventionTips":["displayName <= 128, description <= 2048 code points (null/empty allowed).","Keep description a short summary; link long content externally.","Enforce maxlength via code-point counting in the UI."],"tags":["ai-agent","validation","length-limit","optional-field"],"backgroundTag":null,"analyzedSha":"9b989acdf181d00898f2e8839257bb2b2a3cefe3","analyzedAt":"2026-08-14T07:17:31.569Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}