{"record":{"id":"4e74089cb72f7e36","repo":"apache/iceberg","slug":"illegalargumentexception-with-no-message-unreacha","errorCode":null,"errorMessage":"IllegalArgumentException with no message (unreachable: guarded by preceding Preconditions.checkArgument)","messagePattern":"IllegalArgumentException with no message \\(unreachable: guarded by preceding Preconditions\\.checkArgument\\)","errorType":"exception","errorClass":"java.lang.IllegalArgumentException","httpStatus":null,"severity":"info","filePath":"spark/v3.5/spark/src/main/java/org/apache/iceberg/spark/Spark3Util.java","lineNumber":488,"sourceCode":"\n  @SuppressWarnings(\"unchecked\")\n  private static int findWidth(Transform transform) {\n    for (Expression expr : transform.arguments()) {\n      if (expr instanceof Literal) {\n        if (((Literal) expr).dataType() instanceof IntegerType) {\n          Literal<Integer> lit = (Literal<Integer>) expr;\n          Preconditions.checkArgument(\n              lit.value() > 0, \"Unsupported width for transform: %s\", transform.describe());\n          return lit.value();\n\n        } else if (((Literal) expr).dataType() instanceof LongType) {\n          Literal<Long> lit = (Literal<Long>) expr;\n          Preconditions.checkArgument(\n              lit.value() > 0 && lit.value() < Integer.MAX_VALUE,\n              \"Unsupported width for transform: %s\",\n              transform.describe());\n          if (lit.value() > Integer.MAX_VALUE) {\n            throw new IllegalArgumentException();\n          }\n          return lit.value().intValue();\n        }\n      }\n    }\n\n    throw new IllegalArgumentException(\"Cannot find width for transform: \" + transform.describe());\n  }\n\n  private static String leafName(String[] fieldNames) {\n    Preconditions.checkArgument(\n        fieldNames.length > 0, \"Invalid field name: at least one name is required\");\n    return fieldNames[fieldNames.length - 1];\n  }\n\n  private static String peerName(String[] fieldNames, String fieldName) {\n    if (fieldNames.length > 1) {\n      String[] peerNames = Arrays.copyOf(fieldNames, fieldNames.length);","sourceCodeStart":470,"sourceCodeEnd":506,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/spark/v3.5/spark/src/main/java/org/apache/iceberg/spark/Spark3Util.java#L470-L506","documentation":"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.","triggerScenarios":"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.","commonSituations":"None — this is an internal invariant/dead-code throw; a real invalid width fails earlier with 'Unsupported width for transform'.","solutions":["No action needed; the earlier Preconditions message is what users see","As a code-health fix, delete the unreachable branch"],"exampleFix":"// before\nif (lit.value() > Integer.MAX_VALUE) { throw new IllegalArgumentException(); }\n// after\nreturn lit.value().intValue();","handlingStrategy":"validation","validationCode":"long width = (long) literal.value();\nif (width <= 0 || width >= Integer.MAX_VALUE) throw new IllegalArgumentException(\"Unsupported width for transform: \" + transform.describe());","typeGuard":"boolean isValidWidth(long w) { return w > 0 && w < Integer.MAX_VALUE; }","tryCatchPattern":"try { Spark3Util.toPartitionSpec(schema, parts); } catch (IllegalArgumentException e) { if (e.getMessage().startsWith(\"Unsupported width\")) { /* supply a positive int width */ } else throw e; }","preventionTips":["The messageless throw is unreachable; rely on the guarded 'Unsupported width' message","Always pass positive int-range widths to truncate transforms","Report the dead branch upstream if doing code cleanup"],"tags":["dead-code","unreachable","internal"],"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-23T08:17:48.524Z"}