{"record":{"id":"8492ef1a65fbbf8a","repo":"apache/hadoop","slug":"cannot-truncate-to-a-larger-file-size-current-siz-8492ef","errorCode":null,"errorMessage":"Cannot truncate to a larger file size. Current size: ","messagePattern":"Cannot truncate to a larger file size\\. Current size: ","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/Truncate.java","lineNumber":82,"sourceCode":"      throw new IllegalArgumentException(\"length must be >= 0\");\n    }\n  }\n\n  @Override\n  protected void processArguments(LinkedList<PathData> args)\n      throws IOException {\n    super.processArguments(args);\n    if (waitOpt) waitForRecovery();\n  }\n\n  @Override\n  protected void processPath(PathData item) throws IOException {\n    if(item.stat.isDirectory()) {\n      throw new PathIsDirectoryException(item.toString());\n    }\n    long oldLength = item.stat.getLen();\n    if(newLength > oldLength) {\n      throw new IllegalArgumentException(\n          \"Cannot truncate to a larger file size. Current size: \" + oldLength +\n          \", truncate size: \" + newLength + \".\");\n    }\n    if(item.fs.truncate(item.path, newLength)) {\n      out.println(\"Truncated \" + item + \" to length: \" + newLength);\n    }\n    else if(waitOpt) {\n      waitList.add(item);\n    }\n    else {\n      out.println(\"Truncating \" + item + \" to length: \" + newLength + \". \" +\n          \"Wait for block recovery to complete before further updating this \" +\n          \"file.\");\n    }\n  }\n\n  /**\n   * Wait for all files in waitList to have length equal to newLength.","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/Truncate.java#L64-L100","documentation":"Error \"Cannot truncate to a larger file size. Current size: \" thrown in apache/hadoop.","triggerScenarios":"Thrown by the truncate shell command when the requested new length exceeds the current file size, since truncate cannot grow a file.","commonSituations":"See trigger scenarios.","solutions":["Specify a new length smaller than or equal to the current file size.","Check the file length first with ls/stat before truncating."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}