{"record":{"id":"057f33a876d6e2a6","repo":"apache/hadoop","slug":"length-must-be-0","errorCode":null,"errorMessage":"length must be >= 0","messagePattern":"length must be >= 0","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":64,"sourceCode":"\n  protected long newLength = -1;\n  protected List<PathData> waitList = new LinkedList<>();\n  protected boolean waitOpt = false;\n\n  @Override\n  protected void processOptions(LinkedList<String> args) throws IOException {\n    CommandFormat cf = new CommandFormat(2, Integer.MAX_VALUE, \"w\");\n    cf.parse(args);\n    waitOpt = cf.getOpt(\"w\");\n\n    try {\n      newLength = Long.parseLong(args.removeFirst());\n    } catch(NumberFormatException nfe) {\n      displayWarning(\"Illegal length, a non-negative integer expected\");\n      throw nfe;\n    }\n    if(newLength < 0) {\n      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(","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/Truncate.java#L46-L82","documentation":"Error \"length must be >= 0\" thrown in apache/hadoop.","triggerScenarios":"Thrown by the truncate shell command when the requested new length is negative.","commonSituations":"See trigger scenarios.","solutions":["Provide a non-negative length argument to the truncate command.","Parse and validate the length before calling truncate."],"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"}