{"record":{"id":"b9a6e2ffba9b705f","repo":"apache/iceberg","slug":"string-format-invalid-mode-s-modeasstring","errorCode":null,"errorMessage":"String.format(\"Invalid mode: %s\", modeAsString)","messagePattern":"String\\.format\\(\"Invalid mode: (.+?)\", modeAsString\\)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"api/src/main/java/org/apache/iceberg/actions/DeleteOrphanFiles.java","lineNumber":168,"sourceCode":"  }\n\n  /**\n   * Defines the action behavior when location prefixes (scheme/authority) mismatch.\n   *\n   * <p>{@link #ERROR} - throw an exception. {@link #IGNORE} - no action. {@link #DELETE} - delete\n   * files.\n   */\n  enum PrefixMismatchMode {\n    ERROR,\n    IGNORE,\n    DELETE;\n\n    public static PrefixMismatchMode fromString(String modeAsString) {\n      Preconditions.checkArgument(modeAsString != null, \"Invalid mode: null\");\n      try {\n        return PrefixMismatchMode.valueOf(modeAsString.toUpperCase(Locale.ROOT));\n      } catch (IllegalArgumentException e) {\n        throw new IllegalArgumentException(String.format(\"Invalid mode: %s\", modeAsString), e);\n      }\n    }\n  }\n}\n","sourceCodeStart":150,"sourceCodeEnd":173,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/api/src/main/java/org/apache/iceberg/actions/DeleteOrphanFiles.java#L150-L173","documentation":"PrefixMismatchMode.fromString parses a string into the PrefixMismatchMode enum via valueOf after upper-casing; any string that is not exactly one of the enum constants (case-insensitively) throws IllegalArgumentException with \"Invalid mode: <value>\", chaining the original exception. A null input fails first with \"Invalid mode: null\".","triggerScenarios":"Calling PrefixMismatchMode.fromString with a misspelled or unknown mode string, e.g. \"delete\", \"error\", \"none \" (whitespace), or an empty string, when configuring DeleteOrphanFiles prefix mismatch handling.","commonSituations":"Mode name read from a config file/property that doesn't match an enum constant (e.g., lowercase typos, aliases like \"fail\" instead of \"ERROR\"); null values propagating from unset configuration.","solutions":["Pass one of the exact enum constant names: ERROR, REMOVE, or NONE (case-insensitive).","Trim and normalize the input string before calling fromString.","Handle null explicitly by choosing a default mode instead of passing null."],"exampleFix":"// before\nPrefixMismatchMode mode = PrefixMismatchMode.fromString(config.get(\"mode\")); // \"delete\" -> throws\n// after\nString raw = Optional.ofNullable(config.get(\"mode\")).map(String::trim).orElse(\"NONE\");\nPrefixMismatchMode mode = PrefixMismatchMode.fromString(raw);","handlingStrategy":"validation","validationCode":"String raw = mode == null ? null : mode.trim();\nboolean valid = raw != null && Arrays.stream(PrefixMismatchMode.values())\n    .anyMatch(m -> m.name().equalsIgnoreCase(raw));","typeGuard":"if (modeAsString == null || modeAsString.isBlank()) { modeAsString = \"NONE\"; }","tryCatchPattern":"try { mode = PrefixMismatchMode.fromString(raw); } catch (IllegalArgumentException e) { throw new IllegalArgumentException(\"Unknown prefixMismatchMode '\" + raw + \"'; expected ERROR, REMOVE or NONE\", e); }","preventionTips":["Validate mode strings against PrefixMismatchMode.values() before parsing","Trim user/config input and normalize case","Use the enum constant directly (PrefixMismatchMode.NONE) instead of parsing strings when possible"],"tags":["java","iceberg","enum-parsing","argument-validation"],"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"}