{"record":{"id":"32f5846cd9b26780","repo":"alibaba/spring-ai-alibaba","slug":"maxcachesize-must-be-positive","errorCode":null,"errorMessage":"maxCacheSize must be positive","messagePattern":"maxCacheSize 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":441,"sourceCode":"\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;\n\t\t\treturn this;\n\t\t}\n\n\t\tpublic Builder withName(String name) {\n\t\t\tthis.name = name;\n\t\t\treturn this;\n\t\t}\n","sourceCodeStart":423,"sourceCodeEnd":459,"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#L423-L459","documentation":"Builder.maxCacheSize validates that the fetched-page cache capacity is strictly positive; a non-positive value throws IllegalArgumentException. The tool caches fetched HTML by URL and rejects sizes that would make the cache unusable.","triggerScenarios":"Calling .maxCacheSize(0) or a negative number on the WebFetchTool Builder.","commonSituations":"Reading the cache size from a properties file that returns 0 when unset; experimental config disabling the cache with 0 (disabling is not supported via 0 — omit tuning instead); arithmetic producing a negative size.","solutions":["Pass a positive cache size, e.g. .maxCacheSize(100).","Omit the call to use the library default cache size.","Validate the configured value > 0 before building the tool.","If you want no caching behavior, check the tool's API for an explicit disable option instead of size 0."],"exampleFix":"// before\n.maxCacheSize(0)\n// after\n.maxCacheSize(128)","handlingStrategy":"validation","validationCode":"int size = properties.maxCacheSize();\nif (size <= 0) {\n    throw new IllegalArgumentException(\"webfetch.max-cache-size must be > 0, got \" + size);\n}","typeGuard":"boolean isValidSize(int v) { return v > 0; }","tryCatchPattern":"try {\n    builder.maxCacheSize(size);\n} catch (IllegalArgumentException e) {\n    log.warn(\"invalid maxCacheSize {}, using default\", size);\n    builder = WebFetchTool.builder(chatClient); // restart with defaults\n}","preventionTips":["Never use 0 to 'disable' a cache — check the API for a proper disable mechanism","Parse config with explicit defaults and fail-fast validation","Document valid ranges for tuning properties in your team's config guide"],"tags":["builder","validation","cache"],"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-14T11:17:12.474Z"}