{"record":{"id":"ee208a6d454e70fc","repo":"apache/iceberg","slug":"invalid-unit-s","errorCode":null,"errorMessage":"Invalid unit: %s","messagePattern":"Invalid unit: (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"api/src/main/java/org/apache/iceberg/metrics/MetricsContext.java","lineNumber":53,"sourceCode":"    BYTES(\"bytes\"),\n    COUNT(\"count\");\n\n    private final String displayName;\n\n    Unit(String displayName) {\n      this.displayName = displayName;\n    }\n\n    public String displayName() {\n      return displayName;\n    }\n\n    public static Unit fromDisplayName(String displayName) {\n      Preconditions.checkArgument(null != displayName, \"Invalid unit: null\");\n      try {\n        return Unit.valueOf(displayName.toUpperCase(Locale.ROOT));\n      } catch (IllegalArgumentException e) {\n        throw new IllegalArgumentException(String.format(\"Invalid unit: %s\", displayName), e);\n      }\n    }\n  }\n\n  default void initialize(Map<String, String> properties) {}\n\n  /**\n   * @deprecated will be removed in 2.0.0, use {@link org.apache.iceberg.metrics.Counter} instead.\n   */\n  @Deprecated\n  interface Counter<T extends Number> {\n    /** Increment the counter by a single whole number value (i.e. 1). */\n    void increment();\n\n    /**\n     * Increment the counter by the provided amount.\n     *\n     * @param amount to be incremented","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/api/src/main/java/org/apache/iceberg/metrics/MetricsContext.java#L35-L71","documentation":"MetricsContext.Unit.fromDisplayName converts a user-facing unit string to the Unit enum, uppercasing it first; null throws 'Invalid unit: null' and any string that is not a valid Unit name (bytes, bytes_i32, bytes_i64, count, none, timestamps, time) throws 'Invalid unit: <value>'. It preserves the cause from Unit.valueOf.","triggerScenarios":"Parsing a metrics unit from a table/user property (e.g. 'counter-unit') that is misspelled, empty-but-non-null, or in a different language/lowercase abbreviation like 'b' or 'counts'.","commonSituations":"Config mistakes in properties files (e.g. 'bytese', 'Counts'); users passing human-friendly units like 'bytes' vs enum names like 'BYTES' — note fromDisplayName uppercases, so only exact enum names case-insensitively work; locale issues.","solutions":["Use one of the exact Unit enum names (case-insensitive): bytes, bytes_i32, bytes_i64, count, none, timestamps, time","Check the property value for typos or whitespace before calling fromDisplayName","Guard against null/empty input before conversion","Catch IllegalArgumentException and fall back to a default Unit"],"exampleFix":"// before\nUnit u = Unit.fromDisplayName(props.get(\"unit\"));\n// after\nString raw = props.get(\"unit\");\nUnit u = (raw != null && !raw.isEmpty())\n    ? Unit.fromDisplayName(raw)\n    : Unit.COUNT;","handlingStrategy":"validation","validationCode":"if (displayName == null || displayName.isEmpty()) { default; }","typeGuard":null,"tryCatchPattern":"try { Unit.fromDisplayName(s); } catch (IllegalArgumentException e) { use default; }","preventionTips":["Use exact enum names in configs","Trim inputs","Validate at config load"],"tags":["java","metrics","invalid-enum"],"backgroundTag":"invalid-enum-value","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}