{"record":{"id":"f96f43ca1ba5b89f","repo":"apache/iceberg","slug":"could-not-find-required-length-for-precision-pre","errorCode":null,"errorMessage":"Could not find required length for precision + precision","messagePattern":"Could not find required length for precision \\+ precision","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"api/src/main/java/org/apache/iceberg/types/TypeUtil.java","lineNumber":968,"sourceCode":"\n  static {\n    // for each length, calculate the max precision\n    for (int len = 0; len < MAX_PRECISION.length; len += 1) {\n      MAX_PRECISION[len] = (int) Math.floor(Math.log10(Math.pow(2, 8 * len - 1) - 1));\n    }\n\n    // for each precision, find the first length that can hold it\n    for (int precision = 0; precision < REQUIRED_LENGTH.length; precision += 1) {\n      REQUIRED_LENGTH[precision] = -1;\n      for (int len = 0; len < MAX_PRECISION.length; len += 1) {\n        // find the first length that can hold the precision\n        if (precision <= MAX_PRECISION[len]) {\n          REQUIRED_LENGTH[precision] = len;\n          break;\n        }\n      }\n      if (REQUIRED_LENGTH[precision] < 0) {\n        throw new IllegalStateException(\n            \"Could not find required length for precision \" + precision);\n      }\n    }\n  }\n}\n","sourceCodeStart":950,"sourceCodeEnd":974,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/api/src/main/java/org/apache/iceberg/types/TypeUtil.java#L950-L974","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Use a clean, unmodified Iceberg build: re-download or rebuild from the official release","Check that no bytecode instrumentation, shading, or forking modified TypeUtil's static tables","If you patch Iceberg, ensure precisions up to 39 are covered by MAX_PRECISION lengths up to 23 bytes","Report as a bug with the full stack trace if it occurs on an official artifact"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// validate decimal precision before use\nPreconditions.checkArgument(precision >= 0 && precision < 40, \"Unsupported decimal precision: %s\", precision);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never modify TypeUtil's static lookup tables without recomputing all precisions 0-39","Verify Iceberg artifacts against official releases; avoid patching core classes","Keep decimal precision within 0-38 per the Iceberg spec"],"tags":["java","static-initializer","internal-invariant","decimal-precision"],"backgroundTag":"internal-invariant-violation","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}