{"record":{"id":"8fa0345593471e22","repo":"apache/hadoop","slug":"har-truncate-not-allowed","errorCode":null,"errorMessage":"Har: truncate not allowed","messagePattern":"Har: truncate not allowed","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/HarFileSystem.java","lineNumber":769,"sourceCode":"    throw new IOException(\"Har: setReplication not allowed\");\n  }\n\n  @Override\n  public boolean rename(Path src, Path dst) throws IOException {\n    throw new IOException(\"Har: rename not allowed\");\n  }\n\n  @Override\n  public FSDataOutputStream append(Path f) throws IOException {\n    throw new IOException(\"Har: append not allowed\");\n  }\n\n  /**\n   * Not implemented.\n   */\n  @Override\n  public boolean truncate(Path f, long newLength) throws IOException {\n    throw new IOException(\"Har: truncate not allowed\");\n  }\n\n  /**\n   * Not implemented.\n   */\n  @Override\n  public boolean delete(Path f, boolean recursive) throws IOException { \n    throw new IOException(\"Har: delete not allowed\");\n  }\n\n  /**\n   * liststatus returns the children of a directory \n   * after looking up the index files.\n   */\n  @Override\n  public FileStatus[] listStatus(Path f) throws IOException {\n    //need to see if the file is an index in file\n    //get the filestatus of the archive directory","sourceCodeStart":751,"sourceCodeEnd":787,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/HarFileSystem.java#L751-L787","documentation":"truncate would change the length of a byte range inside a har part file, which is immutable, so the override throws 'Har: truncate not allowed'. Only read APIs are implemented on HarFileSystem.","triggerScenarios":"fs.truncate(harPath, newLength) on any har:// path — tools that shrink files or reclaim space, or generic file-management code that truncates instead of delete+recreate.","commonSituations":"Space-reclamation jobs sweeping all filesystems; ported code that relied on truncate semantics (e.g., HBase-style truncation) and now points at archived data.","solutions":["Truncate the source file on the underlying HDFS and re-create the archive","If the whole archive is disposable, delete the .har directory via the underlying filesystem","Skip truncate calls for read-only filesystems by checking the scheme first"],"exampleFix":"// before\nfs.truncate(new Path(\"har://hdfs-nn:8020/a/data.har/blob.bin\"), 1024);\n\n// after\nhdfs.truncate(new Path(\"hdfs://nn:8020/a/data/blob.bin\"), 1024);\n// then rebuild the archive from the truncated tree","handlingStrategy":"validation","validationCode":"if (\"har\".equals(p.toUri().getScheme())) {\n  throw new UnsupportedOperationException(\"truncate is not supported on har; rebuild the archive instead\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Replace truncate-based space reclamation on archives with full-archive rebuilds","Skip truncate in generic file-management loops when the scheme is har"],"tags":["hadoop","har-filesystem","read-only","truncate"],"backgroundTag":"read-only-filesystem-write","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}