{"record":{"id":"4f6f6dc336ff4549","repo":"alibaba/spring-ai-alibaba","slug":"maxcontentlength-must-be-positive","errorCode":null,"errorMessage":"maxContentLength must be positive","messagePattern":"maxContentLength must be positive","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"spring-ai-alibaba-agent-framework/src/main/java/com/alibaba/cloud/ai/graph/agent/tools/WebFetchTool.java","lineNumber":433,"sourceCode":"\n\t\tprivate int maxCacheSize = 100;\n\n\t\tprivate int maxRetries = 2;\n\n\t\tprivate String name = \"web_fetch\";\n\n\t\tprivate String description = DEFAULT_TOOL_DESCRIPTION;\n\n\t\tprivate Builder(ChatClient chatClient) {\n\t\t\tif (chatClient == null) {\n\t\t\t\tthrow new IllegalArgumentException(\"ChatClient must not be null\");\n\t\t\t}\n\t\t\tthis.chatClient = chatClient;\n\t\t}\n\n\t\tpublic Builder maxContentLength(int maxContentLength) {\n\t\t\tif (maxContentLength <= 0) {\n\t\t\t\tthrow new IllegalArgumentException(\"maxContentLength must be positive\");\n\t\t\t}\n\t\t\tthis.maxContentLength = maxContentLength;\n\t\t\treturn this;\n\t\t}\n\n\t\tpublic Builder maxCacheSize(int maxCacheSize) {\n\t\t\tif (maxCacheSize <= 0) {\n\t\t\t\tthrow new IllegalArgumentException(\"maxCacheSize must be positive\");\n\t\t\t}\n\t\t\tthis.maxCacheSize = maxCacheSize;\n\t\t\treturn this;\n\t\t}\n\n\t\tpublic Builder maxRetries(int maxRetries) {\n\t\t\tif (maxRetries < 0) {\n\t\t\t\tthrow new IllegalArgumentException(\"maxRetries must be non-negative\");\n\t\t\t}\n\t\t\tthis.maxRetries = maxRetries;","sourceCodeStart":415,"sourceCodeEnd":451,"githubUrl":"https://github.com/alibaba/spring-ai-alibaba/blob/f82da0b50f35744c13968191be2b1cd2452ef550/spring-ai-alibaba-agent-framework/src/main/java/com/alibaba/cloud/ai/graph/agent/tools/WebFetchTool.java#L415-L451","documentation":"Builder.maxContentLength validates that the configured truncation limit for fetched content is strictly positive; zero or negative values throw IllegalArgumentException. This guards against nonsensical limits that would truncate all content.","triggerScenarios":"Calling .maxContentLength(0) or a negative value on the WebFetchTool Builder.","commonSituations":"Copy-paste config where the value comes from properties that default to 0; typo like maxContentLength(-1); computing the limit from an empty/unparsed config value.","solutions":["Pass a positive integer, e.g. .maxContentLength(100_000).","If loading from configuration, validate the property > 0 before building.","Omit the call to keep the library default.","Clamp with Math.max(1, configuredValue) if the value is dynamic."],"exampleFix":"// before\n.maxContentLength(0)\n// after\n.maxContentLength(200_000)","handlingStrategy":"validation","validationCode":"int limit = properties.maxContentLength();\nif (limit <= 0) {\n    throw new IllegalArgumentException(\"webfetch.max-content-length must be > 0, got \" + limit);\n}","typeGuard":"boolean isValidSize(int v) { return v > 0; }","tryCatchPattern":"try {\n    builder.maxContentLength(limit);\n} catch (IllegalArgumentException e) {\n    log.warn(\"invalid maxContentLength {}, using default\", limit);\n    builder.maxContentLength(DEFAULT_CONTENT_LENGTH);\n}","preventionTips":["Validate configuration properties before passing them to builders","Give config defaults in application.yml so values are never 0 by omission","Unit-test builder configuration with your real property values"],"tags":["builder","validation","configuration"],"backgroundTag":"invalid-argument-value","analyzedSha":"f82da0b50f35744c13968191be2b1cd2452ef550","analyzedAt":"2026-09-09T15:32:42.421Z","contentChangedAt":"2026-09-09T15:32:42.421Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}