apache/hadoop · error · IllegalArgumentException

length must be >= 0

Error message

length must be >= 0

What it means

Error "length must be >= 0" thrown in apache/hadoop.

Source

Thrown at hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/Truncate.java:64

  protected long newLength = -1;
  protected List<PathData> waitList = new LinkedList<>();
  protected boolean waitOpt = false;

  @Override
  protected void processOptions(LinkedList<String> args) throws IOException {
    CommandFormat cf = new CommandFormat(2, Integer.MAX_VALUE, "w");
    cf.parse(args);
    waitOpt = cf.getOpt("w");

    try {
      newLength = Long.parseLong(args.removeFirst());
    } catch(NumberFormatException nfe) {
      displayWarning("Illegal length, a non-negative integer expected");
      throw nfe;
    }
    if(newLength < 0) {
      throw new IllegalArgumentException("length must be >= 0");
    }
  }

  @Override
  protected void processArguments(LinkedList<PathData> args)
      throws IOException {
    super.processArguments(args);
    if (waitOpt) waitForRecovery();
  }

  @Override
  protected void processPath(PathData item) throws IOException {
    if(item.stat.isDirectory()) {
      throw new PathIsDirectoryException(item.toString());
    }
    long oldLength = item.stat.getLen();
    if(newLength > oldLength) {
      throw new IllegalArgumentException(

View on GitHub (pinned to 2add963021)

Solutions

  1. Provide a non-negative length argument to the truncate command.
  2. Parse and validate the length before calling truncate.

When it happens

Trigger: Thrown by the truncate shell command when the requested new length is negative.

Common situations: See trigger scenarios.


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