{"record":{"id":"4886602a5acdca8c","repo":"alibaba/spring-ai-alibaba","slug":"maxcachedthreads-must-be-greater-than-or-equal-to-488660","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/h2/H2Saver.java","lineNumber":558,"sourceCode":"\n\t\tpublic Builder user(String user) {\n\t\t\tthis.user = user;\n\t\t\treturn this;\n\t\t}\n\n\t\tpublic Builder password(String password) {\n\t\t\tthis.password = password;\n\t\t\treturn this;\n\t\t}\n\n\t\tpublic Builder createOption(CreateOption createOption) {\n\t\t\tthis.createOption = requireNonNull(createOption, \"createOption cannot be null\");\n\t\t\treturn this;\n\t\t}\n\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\tprivate String requireNotBlank(String value, String name) {\n\t\t\tif (requireNonNull(value, format(\"'%s' cannot be null\", name)).isBlank()) {\n\t\t\t\tthrow new IllegalArgumentException(format(\"'%s' cannot be blank\", name));\n\t\t\t}\n\t\t\treturn value;\n\t\t}\n\n\t\tpublic H2Saver build() {\n\t\t\tif (stateSerializer == null) {\n\t\t\t\tthis.stateSerializer = StateGraph.DEFAULT_JACKSON_SERIALIZER;\n\t\t\t}\n\t\t\tif (dataSource == null) {\n\t\t\t\tdataSource = new DriverManagerDataSource(requireNotBlank(jdbcUrl, \"jdbcUrl\"), user, password);","sourceCodeStart":540,"sourceCodeEnd":576,"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/h2/H2Saver.java#L540-L576","documentation":"The H2Saver.Builder.maxCachedThreads method validates its argument eagerly and throws IllegalArgumentException if a negative value is passed. maxCachedThreads bounds the number of thread sessions the saver keeps cached, so a negative bound is meaningless and rejected at build time.","triggerScenarios":"Calling builder.maxCachedThreads(n) with any n < 0, typically n coming from a computed value, a config property defaulting to -1 for 'unlimited', or a sign error.","commonSituations":"Mapping a config key like 'saver.max-cached-threads=-1' intending 'unlimited'; parsing user input without clamping; arithmetic producing a negative value.","solutions":["Pass a non-negative value; use 0 to disable thread caching rather than a negative number.","Clamp or sanitize external config before calling the builder: Math.max(0, configured).","If 'unlimited' was intended, omit the call and use the builder's default."],"exampleFix":"// before: -1 meaning 'unlimited' from config\nbuilder.maxCachedThreads(config.maxCachedThreads()); // throws\n// after: clamp to valid range\nbuilder.maxCachedThreads(Math.max(0, config.maxCachedThreads()));","handlingStrategy":"validation","validationCode":"if (configuredMaxCachedThreads < 0) throw new IllegalArgumentException(\"saver.max-cached-threads must be >= 0 (0 disables caching)\");","typeGuard":"int safeThreads(Integer v) { return v == null ? DEFAULT : Math.max(0, v); }","tryCatchPattern":"try { builder.maxCachedThreads(n); }\ncatch (IllegalArgumentException e) { builder.maxCachedThreads(Math.max(0, n)); }","preventionTips":["Never use -1 for 'unlimited' with this builder — omit the call instead","Clamp all numeric config before passing to builders","Unit-test builder calls fed from configuration"],"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"}