apache/hadoop · error · IllegalArgumentException

Cannot truncate to a larger file size. Current size:

Error message

Cannot truncate to a larger file size. Current size: 

What it means

Error "Cannot truncate to a larger file size. Current size: " thrown in apache/hadoop.

Source

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

      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(
          "Cannot truncate to a larger file size. Current size: " + oldLength +
          ", truncate size: " + newLength + ".");
    }
    if(item.fs.truncate(item.path, newLength)) {
      out.println("Truncated " + item + " to length: " + newLength);
    }
    else if(waitOpt) {
      waitList.add(item);
    }
    else {
      out.println("Truncating " + item + " to length: " + newLength + ". " +
          "Wait for block recovery to complete before further updating this " +
          "file.");
    }
  }

  /**
   * Wait for all files in waitList to have length equal to newLength.

View on GitHub (pinned to 2add963021)

Solutions

  1. Specify a new length smaller than or equal to the current file size.
  2. Check the file length first with ls/stat before truncating.

When it happens

Trigger: Thrown by the truncate shell command when the requested new length exceeds the current file size, since truncate cannot grow a file.

Common situations: See trigger scenarios.


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