{"record":{"id":"24c3088aa30296c8","repo":"xai-org/x-algorithm","slug":"batch-size-must-be-a-positive-integer","errorCode":null,"errorMessage":"batch size must be a positive integer","messagePattern":"batch size must be a positive integer","errorType":"validation","errorClass":"FunctionFailure","httpStatus":null,"severity":"error","filePath":"botmaker/src/java/com/twitter/botmaker/function/collection/Any.java","lineNumber":117,"sourceCode":"                return Boolean.FALSE;\n              } catch (Exception e) {\n                throw FunctionFailure.wrap(e, getAstNode(), context);\n              }\n            }\n          };\n        } else {\n          return new Extractor<Runtime>(this, children) {\n            @Override\n            public Future run(Context<Runtime> context) {\n              Future<Object> collectionExtractionFuture = context.run(collectionExtractor);\n              Future<Object> batchSizeExtractionFuture = context.run(batchSizeExtractor);\n              return Futures.join(collectionExtractionFuture, batchSizeExtractionFuture)\n                  .flatMap(collectionAndBatchSize -> {\n                        Collection<Object> collection =\n                            (Collection<Object>) collectionAndBatchSize._1();\n                        int batchSize = ((Long) collectionAndBatchSize._2()).intValue();\n                        if (batchSize <= 0) {\n                          throw new FunctionFailure(getAstNode(),\n                              context.getStackFrames(),\n                              new IllegalArgumentException(\n                                  \"batch size must be a positive integer\"));\n                        }\n\n                        if (collection.isEmpty()) {\n                          return FUTURE_FALSE;\n                        }\n\n                        return evaluate(\n                            context,\n                            varName,\n                            new ArrayList<>(collection),\n                            0,\n                            conditionExtractor,\n                            batchSize\n                        );\n                      }","sourceCodeStart":99,"sourceCodeEnd":135,"githubUrl":"https://github.com/xai-org/x-algorithm/blob/24c60942c5c5fdad3a6addffb4c6e6d2f228f04f/botmaker/src/java/com/twitter/botmaker/function/collection/Any.java#L99-L135","documentation":"Any(batchSize) requires the second argument (batch size) to evaluate to a positive integer. When the joined collection and batch-size futures resolve, a batchSize of 0 or negative triggers FunctionFailure wrapping IllegalArgumentException. It is a runtime error, so the bad value only surfaces when the rule executes.","triggerScenarios":"Calling Any(collection, batchSize) where batchSize evaluates to 0 or a negative Long at runtime, e.g. Any(x, 0), or batchSize derived from user data/another function that returns 0.","commonSituations":"Hardcoding a batch size of 0, using a computed batch size (e.g. length of an empty collection) that collapses to 0, or copying an example with a placeholder value.","solutions":["Set the batch size to a positive integer literal such as 1 or 10","If batchSize is computed, wrap it with Max(1, expr) or guard it before use","Check the rule's parameters/constants feeding the second argument of Any()"],"exampleFix":"// before\nAny(items, 0)\n// after\nAny(items, 10)","handlingStrategy":"validation","validationCode":"// before calling Any: ensure batchSize > 0\nlong batchSize = getBatchSize();\nif (batchSize <= 0) { batchSize = DEFAULT_BATCH_SIZE; }\ncollection = Any(items, batchSize);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never hardcode 0 as a batch size","Validate computed batch sizes with a Max(1, x) style guard","Treat FunctionFailure with 'batch size must be a positive integer' as a configuration bug, not transient"],"tags":["botmaker","runtime","batch-size","validation","function-failure"],"backgroundTag":"invalid-function-arguments","analyzedSha":"24c60942c5c5fdad3a6addffb4c6e6d2f228f04f","analyzedAt":"2026-08-28T11:40:14.686Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}