apache/iceberg · info · java.lang.IllegalArgumentException

IllegalArgumentException with no message (unreachable…

Error message

IllegalArgumentException with no message (unreachable: guarded by preceding Preconditions.checkArgument)

What it means

In findWidth, after Preconditions.checkArgument already rejects widths <= 0 or >= Integer.MAX_VALUE, the following `if (lit.value() > Integer.MAX_VALUE) throw new IllegalArgumentException();` is unreachable dead code — the messageless IllegalArgumentException can never actually be thrown to users.

Solutions

  1. No action needed; the earlier Preconditions message is what users see
  2. As a code-health fix, delete the unreachable branch

Example fix

// before
if (lit.value() > Integer.MAX_VALUE) { throw new IllegalArgumentException(); }
// after
return lit.value().intValue();
Defensive patterns

Strategy: validation

Validate before calling

long width = (long) literal.value();
if (width <= 0 || width >= Integer.MAX_VALUE) throw new IllegalArgumentException("Unsupported width for transform: " + transform.describe());

Type guard

boolean isValidWidth(long w) { return w > 0 && w < Integer.MAX_VALUE; }

Try / catch

try { Spark3Util.toPartitionSpec(schema, parts); } catch (IllegalArgumentException e) { if (e.getMessage().startsWith("Unsupported width")) { /* supply a positive int width */ } else throw e; }

Prevention

When it happens

Trigger: Not triggerable in practice: the guard above it guarantees lit.value() is in (0, Integer.MAX_VALUE), so the condition is always false. Listed for completeness of the throw site.

Common situations: None — this is an internal invariant/dead-code throw; a real invalid width fails earlier with 'Unsupported width for transform'.

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/4e74089cb72f7e36. Report an issue: GitHub.

Appendix: source

Thrown at spark/v3.5/spark/src/main/java/org/apache/iceberg/spark/Spark3Util.java:488

  @SuppressWarnings("unchecked")
  private static int findWidth(Transform transform) {
    for (Expression expr : transform.arguments()) {
      if (expr instanceof Literal) {
        if (((Literal) expr).dataType() instanceof IntegerType) {
          Literal<Integer> lit = (Literal<Integer>) expr;
          Preconditions.checkArgument(
              lit.value() > 0, "Unsupported width for transform: %s", transform.describe());
          return lit.value();

        } else if (((Literal) expr).dataType() instanceof LongType) {
          Literal<Long> lit = (Literal<Long>) expr;
          Preconditions.checkArgument(
              lit.value() > 0 && lit.value() < Integer.MAX_VALUE,
              "Unsupported width for transform: %s",
              transform.describe());
          if (lit.value() > Integer.MAX_VALUE) {
            throw new IllegalArgumentException();
          }
          return lit.value().intValue();
        }
      }
    }

    throw new IllegalArgumentException("Cannot find width for transform: " + transform.describe());
  }

  private static String leafName(String[] fieldNames) {
    Preconditions.checkArgument(
        fieldNames.length > 0, "Invalid field name: at least one name is required");
    return fieldNames[fieldNames.length - 1];
  }

  private static String peerName(String[] fieldNames, String fieldName) {
    if (fieldNames.length > 1) {
      String[] peerNames = Arrays.copyOf(fieldNames, fieldNames.length);

View on GitHub (pinned to 86d9c8fc54)