{"record":{"id":"11fdcf3775d447b5","repo":"apache/beam","slug":"expected-size-0-but-received-size","errorCode":null,"errorMessage":"Expected size >= 0 but received ${size}.","messagePattern":"Expected size >= 0 but received (.+?)\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/reflect/ByteBuddyDoFnInvokerFactory.java","lineNumber":576,"sourceCode":"  }\n\n  public static class DefaultGetSize {\n    /** Uses {@link HasProgress} to produce the size. */\n    @SuppressWarnings(\"unused\")\n    public static <InputT, OutputT> double invokeGetSize(\n        DoFnInvoker.ArgumentProvider<InputT, OutputT> argumentProvider) {\n      if (argumentProvider.restrictionTracker() instanceof HasProgress) {\n        return ((HasProgress) argumentProvider.restrictionTracker())\n            .getProgress()\n            .getWorkRemaining();\n      } else {\n        return 0.0;\n      }\n    }\n\n    public static double validateSize(double size) {\n      if (size < 0) {\n        throw new IllegalArgumentException(\n            String.format(\"Expected size >= 0 but received %s.\", size));\n      }\n      return size;\n    }\n  }\n\n  /**\n   * Generates a type suffix string for use in invoker class names.\n   *\n   * <p>This creates a unique suffix based on the input and output type descriptors to avoid class\n   * name collisions when the same DoFn class is used with different generic types.\n   *\n   * <p>The format is: {@code DoFnInvoker$<8-digit hex hash>}\n   *\n   * @param inputType the input type descriptor\n   * @param outputType the output type descriptor\n   * @return a string suffix for the invoker class name\n   */","sourceCodeStart":558,"sourceCodeEnd":594,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/reflect/ByteBuddyDoFnInvokerFactory.java#L558-L594","documentation":"This validation is used by default restriction-tracker helpers for splittable DoFns: a restriction's reported size must be non-negative for progress/fraction estimation. validateSize throws IllegalArgumentException when a negative size is claimed.","triggerScenarios":"A custom RestrictionTracker or restriction reports a negative value from its size/progress method (e.g. end offset smaller than start), which the ByteBuddy delegation passes to validateSize.","commonSituations":"Miscomputed restriction in a custom splittable DoFn; overflow or unit mistakes when computing byte/element counts; empty input returning a negative sentinel.","solutions":["Clamp the reported size to >= 0 in the RestrictionTracker (Math.max(0, end - start)).","Fix the restriction computation so size is derived correctly from actual data bounds.","Return 0 for empty restrictions rather than a negative value."],"exampleFix":"// before\npublic double getSize() { return end - start; } // negative if end < start\n// after\npublic double getSize() { return Math.max(0, end - start); }","handlingStrategy":"validation","validationCode":"double size = tracker.currentRestriction().getBodySize();\nif (size < 0) throw new IllegalStateException(\"restriction size must be >= 0, got \" + size);","typeGuard":"boolean isValidSize(double size) { return size >= 0 && !Double.isNaN(size); }","tryCatchPattern":null,"preventionTips":["Compute restriction size as Math.max(0, end - start) in custom RestrictionTrackers.","Unit-test splittable DoFn restrictions with empty and inverted bounds.","Return 0 for empty restrictions instead of negative sentinels."],"tags":["java","apache-beam","splittable-dofn","restriction","validation"],"backgroundTag":"invalid-argument-value","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}