apache/iceberg · error

Could not find required length for precision + precision

Error message

Could not find required length for precision + precision

What it means

Thrown from TypeUtil's static initializer when building the decimal precision-to-byte-length lookup tables. It means no byte length (0-23) could hold the given decimal precision, which is impossible for precisions 0-39; the table building logic guarantees REQUIRED_LENGTH[precision] >= 0 for all valid precisions. This is effectively an internal invariant violation that would only trigger if the table constants or loop bounds are corrupted — users should never see it.

Source

Thrown at api/src/main/java/org/apache/iceberg/types/TypeUtil.java:968

  static {
    // for each length, calculate the max precision
    for (int len = 0; len < MAX_PRECISION.length; len += 1) {
      MAX_PRECISION[len] = (int) Math.floor(Math.log10(Math.pow(2, 8 * len - 1) - 1));
    }

    // for each precision, find the first length that can hold it
    for (int precision = 0; precision < REQUIRED_LENGTH.length; precision += 1) {
      REQUIRED_LENGTH[precision] = -1;
      for (int len = 0; len < MAX_PRECISION.length; len += 1) {
        // find the first length that can hold the precision
        if (precision <= MAX_PRECISION[len]) {
          REQUIRED_LENGTH[precision] = len;
          break;
        }
      }
      if (REQUIRED_LENGTH[precision] < 0) {
        throw new IllegalStateException(
            "Could not find required length for precision " + precision);
      }
    }
  }
}

View on GitHub (pinned to 86d9c8fc54)

Solutions

  1. Use a clean, unmodified Iceberg build: re-download or rebuild from the official release
  2. Check that no bytecode instrumentation, shading, or forking modified TypeUtil's static tables
  3. If you patch Iceberg, ensure precisions up to 39 are covered by MAX_PRECISION lengths up to 23 bytes
  4. Report as a bug with the full stack trace if it occurs on an official artifact
Defensive patterns

Strategy: validation

Validate before calling

// validate decimal precision before use
Preconditions.checkArgument(precision >= 0 && precision < 40, "Unsupported decimal precision: %s", precision);

Prevention

When it happens

Trigger: Class-initialization failure of TypeUtil because the static table builder found a precision in 0..39 whose REQUIRED_LENGTH remained -1 after scanning all MAX_PRECISION lengths. Only possible if MAX_PRECISION/REQUIRED_LENGTH constants or the loop logic are modified.

Common situations: A broken or modified Iceberg build, class file corruption, or an agent/weaving tool altering static state; also seen if a fork patches the decimal tables incorrectly. Not caused by user configuration.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


AI-assisted analysis of apache/iceberg@86d9c8fc54 (2026-09-12). Data as JSON: /api/errors/f96f43ca1ba5b89f. Report an issue: GitHub.