{"record":{"id":"136b5720b309bc2f","repo":"alibaba/spring-ai-alibaba","slug":"maxcachedthreads-must-be-greater-than-or-equal-to-136b57","errorCode":null,"errorMessage":"maxCachedThreads must be greater than or equal to 0","messagePattern":"maxCachedThreads must be greater than or equal to 0","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"spring-ai-alibaba-graph-core/src/main/java/com/alibaba/cloud/ai/graph/checkpoint/savers/file/FileSystemSaver.java","lineNumber":442,"sourceCode":"\n\t\tpublic Builder targetFolder(Path targetFolder) {\n\t\t\tthis.targetFolder = targetFolder;\n\t\t\treturn this;\n\t\t}\n\n\t\tpublic Builder stateSerializer(StateSerializer stateSerializer) {\n\t\t\tthis.stateSerializer = stateSerializer;\n\t\t\treturn this;\n\t\t}\n\n\t\t/**\n\t\t * Sets the maximum number of latest checkpoints retained in memory.\n\t\t * @param maxCachedThreads max cached threads, or 0 to disable the cache\n\t\t * @return this builder\n\t\t */\n\t\tpublic Builder maxCachedThreads(int maxCachedThreads) {\n\t\t\tif (maxCachedThreads < 0) {\n\t\t\t\tthrow new IllegalArgumentException(\"maxCachedThreads must be greater than or equal to 0\");\n\t\t\t}\n\t\t\tthis.maxCachedThreads = maxCachedThreads;\n\t\t\treturn this;\n\t\t}\n\n\t\t/**\n\t\t * Builds a new FileSystemSaver instance.\n\t\t * @return a new FileSystemSaver instance\n\t\t * @throws IllegalArgumentException if targetFolder is null\n\t\t */\n\t\tpublic FileSystemSaver build() {\n\t\t\treturn new FileSystemSaver(this);\n\t\t}\n\t}\n\n}\n","sourceCodeStart":424,"sourceCodeEnd":459,"githubUrl":"https://github.com/alibaba/spring-ai-alibaba/blob/f82da0b50f35744c13968191be2b1cd2452ef550/spring-ai-alibaba-graph-core/src/main/java/com/alibaba/cloud/ai/graph/checkpoint/savers/file/FileSystemSaver.java#L424-L459","documentation":"FileSystemSaver.Builder.maxCachedThreads sets how many threads' latest checkpoints are kept in memory (0 disables the cache). Negative values are rejected with IllegalArgumentException when the builder method is called.","triggerScenarios":"fileSystemSaverBuilder.maxCachedThreads(-n) with any negative integer, often sourced from application configuration.","commonSituations":"Config file typo (negative number), or computing the value from an expression that can go negative under some environments.","solutions":["Pass 0 or a positive integer to maxCachedThreads","Validate/clamp the value read from configuration before applying it","Fix the config source emitting the negative value"],"exampleFix":"// before\nbuilder.maxCachedThreads(props.getThreads()); // could be -5\n// after\nbuilder.maxCachedThreads(Math.max(0, props.getThreads()));","handlingStrategy":"validation","validationCode":"if (builderMaxCachedThreads < 0) throw new IllegalArgumentException(\"must be >= 0\");","typeGuard":"int clampNonNegative(int v) { return Math.max(0, v); }","tryCatchPattern":"try { builder.maxCachedThreads(v); } catch (IllegalArgumentException e) { builder.maxCachedThreads(0); }","preventionTips":["Validate numeric config before applying to builders","Use Math.max(0, value) at config load time","Cover builder validation with tests"],"tags":["filesystem","checkpoint","builder-validation"],"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"}