{"record":{"id":"e713034a58ba0828","repo":"apache/beam","slug":"targetbatchdurationsecswithfixedcost-f-must-be-positive","errorCode":null,"errorMessage":"targetBatchDurationSecsWithFixedCost (%f) must be positive","messagePattern":"targetBatchDurationSecsWithFixedCost \\((.+?)\\) must be positive","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/BatchElements.java","lineNumber":259,"sourceCode":"        if (minBatchSize > maxBatchSize) {\n          throw new IllegalArgumentException(\n              String.format(\n                  \"Minimum (%d) must not be greater than maximum (%d)\",\n                  minBatchSize, maxBatchSize));\n        }\n        if (!(targetBatchOverhead > 0 && targetBatchOverhead <= 1)) {\n          throw new IllegalArgumentException(\n              String.format(\n                  \"targetBatchOverhead (%f) must be between 0 and 1\", targetBatchOverhead));\n        }\n        if (targetBatchDurationSecs <= 0) {\n          throw new IllegalArgumentException(\n              String.format(\n                  \"targetBatchDurationSecs (%f) must be positive\", targetBatchDurationSecs));\n        }\n        if (targetBatchDurationSecsWithFixedCost != -1\n            && targetBatchDurationSecsWithFixedCost <= 0) {\n          throw new IllegalArgumentException(\n              String.format(\n                  \"targetBatchDurationSecsWithFixedCost (%f) must be positive\",\n                  targetBatchDurationSecsWithFixedCost));\n        }\n      }\n    }\n  }\n\n  static class BatchSizeEstimator implements Serializable {\n    private List<long[]> data = new ArrayList<>();\n    private final BatchConfig config;\n    private @Nullable Integer replayLastBatchSize = null; // null = no replay pending\n    private final Map<Integer, Integer>\n        batchSizeNumSeen; // tracks how many times each batch size seen\n    private boolean ignoreNextTiming = false;\n    private final Random random;\n\n    private static final int MAX_DATA_POINTS = 100;","sourceCodeStart":241,"sourceCodeEnd":277,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/BatchElements.java#L241-L277","documentation":"BatchConfig.validate rejected targetBatchDurationSecsWithFixedCost because it was <= 0. This variant expresses the target batching duration split into a fixed per-batch cost plus a per-element cost; a non-positive total makes batch sizing unsolvable, so the builder refuses it during build().","triggerScenarios":"Calling withTargetBatchDurationWithFixedCost(x) with x <= 0 and x != -1 (e.g. 0 or -0.5) then build().","commonSituations":"Config value 0 reaching the builder; using -1 intending 'unset' is fine, but other negatives fail; unit conversion producing 0.0 for very small durations.","solutions":["Pass a positive seconds value, or leave unset (-1 default)","Coerce 0/negative config values to unset before building","Validate at config load"],"exampleFix":"// before\n.withTargetBatchDurationWithFixedCost(0)\n// after\n.withTargetBatchDurationWithFixedCost(0.5) // or omit","handlingStrategy":"validation","validationCode":"if (d != -1 && d <= 0) throw new IllegalArgumentException(\"targetBatchDurationSecsWithFixedCost must be positive or -1 (unset), got \" + d);","typeGuard":null,"tryCatchPattern":"try {\n  return builder.withTargetBatchDurationWithFixedCost(d);\n} catch (IllegalArgumentException e) {\n  LOG.error(\"Fixed-cost batch duration must be positive or unset\", e); throw e;\n}","preventionTips":["Treat -1 as the only valid 'unset' sentinel; never pass other negatives","Coerce zero config values to unset before building","Validate at config load time"],"tags":["java","builder-validation","batching"],"backgroundTag":"value-out-of-range","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}