{"record":{"id":"822a852eef8b183a","repo":"alibaba/spring-ai-alibaba","slug":"maxiterations-must-be-0","errorCode":null,"errorMessage":"maxIterations must be > 0!","messagePattern":"maxIterations must be > 0!","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"warning","filePath":"spring-ai-alibaba-graph-core/src/main/java/com/alibaba/cloud/ai/graph/CompiledGraph.java","lineNumber":541,"sourceCode":"\n\t/**\n\t * Package-private access to maxIterations for ReactiveNodeGenerator\n\t */\n\tpublic int getMaxIterations() {\n\t\treturn maxIterations;\n\t}\n\n\t/**\n\t * Sets the maximum number of iterations for the graph execution.\n\t *\n\t * @param maxIterations the maximum number of iterations\n\t * @throws IllegalArgumentException if maxIterations is less than or equal to 0\n\t * @deprecated use CompileConfig.recursionLimit() instead\n\t */\n\t@Deprecated(forRemoval = true)\n\tpublic void setMaxIterations(int maxIterations) {\n\t\tif (maxIterations <= 0) {\n\t\t\tthrow new IllegalArgumentException(\"maxIterations must be > 0!\");\n\t\t}\n\t\tthis.maxIterations = maxIterations;\n\t}\n\n\tpublic GraphResponse<NodeOutput> invokeAndGetResponse(Map<String, Object> inputs, RunnableConfig config) {\n\t\treturn graphResponseStream(inputs, config).last().block();\n\t}\n\n\tpublic GraphResponse<NodeOutput> invokeAndGetResponse(OverAllState state, RunnableConfig config) {\n\t\treturn graphResponseStream(state, config).last().block();\n\t}\n\n\tpublic Flux<GraphResponse<NodeOutput>> graphResponseStream(Map<String, Object> inputs, RunnableConfig config) {\n\t\treturn graphResponseStream(stateCreate(inputs), config);\n\t}\n\n\tpublic Flux<GraphResponse<NodeOutput>> graphResponseStream(OverAllState state, RunnableConfig config) {\n\t\tObjects.requireNonNull(config, \"config cannot be null\");","sourceCodeStart":523,"sourceCodeEnd":559,"githubUrl":"https://github.com/alibaba/spring-ai-alibaba/blob/f82da0b50f35744c13968191be2b1cd2452ef550/spring-ai-alibaba-graph-core/src/main/java/com/alibaba/cloud/ai/graph/CompiledGraph.java#L523-L559","documentation":"Deprecated CompiledGraph.setMaxIterations enforces a positive iteration cap, mirroring CompileConfig.recursionLimit. Passing <= 0 throws IllegalArgumentException. The method is deprecated for removal.","triggerScenarios":"Calling setMaxIterations(0) or with a negative value — e.g. from the deprecated test path longSelfLoopShouldCompleteWithoutStackOverflow or legacy config code.","commonSituations":"Migrated code setting maxIterations from config that defaults to 0; copy-pasted builder code that used to allow 0 meaning 'unlimited'.","solutions":["Pass a positive value, e.g. setMaxIterations(25).","Migrate to CompileConfig.builder().recursionLimit(n).build() and compile the graph with it.","Remove setMaxIterations calls entirely; they are deprecated for removal."],"exampleFix":"// before\ncompiledGraph.setMaxIterations(0);\n// after\nCompileConfig cfg = CompileConfig.builder().recursionLimit(25).build();\nvar compiled = graph.compile(cfg);","handlingStrategy":"validation","validationCode":"if (maxIterations <= 0) throw new IllegalArgumentException(\"maxIterations must be positive\");","typeGuard":"Integer safeMaxIterations(Integer v) { return (v == null || v <= 0) ? 25 : v; }","tryCatchPattern":"try { graph.setMaxIterations(n); } catch (IllegalArgumentException e) { log.warn(\"Invalid maxIterations {}; using recursionLimit instead\", n); }","preventionTips":["Migrate off setMaxIterations to CompileConfig.recursionLimit.","Clamp config-derived iteration values to a positive minimum.","Grep the codebase for setMaxIterations to remove legacy calls."],"tags":["deprecated-api","configuration","validation"],"backgroundTag":"deprecated-api-usage","analyzedSha":"f82da0b50f35744c13968191be2b1cd2452ef550","analyzedAt":"2026-09-09T15:32:42.421Z","contentChangedAt":"2026-09-09T15:32:42.421Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}