apache/hadoop · error · UnsupportedOperationException

Unknown option: {}

Error message

Unknown option: {}

What it means

The fs2img CLI ('hadoop fs2img') parses options with commons-cli and dispatches each recognized option in a switch; any option that parses but has no handler falls to default and throws UnsupportedOperationException('Unknown option: <opt>'). The supported set in this build is: -o (output path), -u (UGIResolver class), -b (BlockAliasMap class), -i (BlockResolver class), -c (cache size), -cid (cluster ID), -bpid (block pool ID), -h (usage). You hit it when passing an option this build does not know.

Source

Thrown at hadoop-tools/hadoop-fs2img/src/main/java/org/apache/hadoop/hdfs/server/namenode/FileSystemImage.java:128

      case "b":
        opts.blocks(
            Class.forName(o.getValue()).asSubclass(BlockAliasMap.class));
        break;
      case "i":
        opts.blockIds(
            Class.forName(o.getValue()).asSubclass(BlockResolver.class));
        break;
      case "c":
        opts.cache(Integer.parseInt(o.getValue()));
        break;
      case "cid":
        opts.clusterID(o.getValue());
        break;
      case "bpid":
        opts.blockPoolID(o.getValue());
        break;
      default:
        throw new UnsupportedOperationException(
            "Unknown option: " + o.getOpt());
      }
    }

    String[] rem = cmd.getArgs();
    if (rem.length != 1) {
      printUsage();
      return -1;
    }

    try (ImageWriter w = new ImageWriter(opts)) {
      for (TreePath e : new FSTreeWalk(new Path(rem[0]), getConf())) {
        w.accept(e); // add and continue
      }
    }
    return 0;
  }

View on GitHub (pinned to 2add963021)

Solutions

  1. Run 'hadoop fs2img -h' and use only the options it lists.
  2. Correct or remove the offending flag from the command line named in the message.
  3. Align the script with the Hadoop version actually deployed on the host.

Example fix

# before
hadoop fs2img --output file:///img /data

# after
hadoop fs2img -o file:///img /data
Defensive patterns

Strategy: validation

Validate before calling

Set<String> supported = new HashSet<>(Arrays.asList("o", "u", "b", "i", "c", "cid", "bpid", "h"));
for (String a : args) {
  if (a.startsWith("-") && !supported.contains(a.substring(1))) {
    throw new IllegalArgumentException("Unsupported fs2img option " + a + "; run 'hadoop fs2img -h'");
  }
}

Try / catch

try {
  exitCode = fs2img.run(args);
} catch (UnsupportedOperationException e) {
  if (e.getMessage().startsWith("Unknown option:")) {
    // print usage and correct the flag named in the message
  }
}

Prevention

When it happens

Trigger: Passing a flag outside the supported set, e.g. a long option like --output that this version does not define, or an option added in a different Hadoop release; also class-name options misspelled so they land in an unexpected branch.

Common situations: Version drift: a script written against newer/older fs2img documentation; typos like -class instead of -u; assuming hadoop-distcp-style options work for fs2img.

Related errors


AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22). Data as JSON: /api/errors/2a719728c32e8197. Report an issue: GitHub.