{"record":{"id":"1bf7b0e6bea01962","repo":"juicedata/juicefs","slug":"errno-errno-path-via-error-maps-errno-t","errorCode":null,"errorMessage":"errno: ${errno} ${path} (via error(); maps errno to PathPermissionException/FileNotFoundException/AccessControlException/etc.)","messagePattern":"errno: (.+?) (.+?) \\(via error\\(\\); maps errno to PathPermissionException/FileNotFoundException/AccessControlException/etc\\.\\)","errorType":"exception","errorClass":"java.io.IOException","httpStatus":null,"severity":"error","filePath":"sdk/java/src/main/java/io/juicefs/JuiceFileSystemImpl.java","lineNumber":1731,"sourceCode":"      try {\n        if (!checkParentPathAccess(p, FsAction.WRITE_EXECUTE, \"delete\")) {\n          return superGroupFileSystem.delete(p, recursive);\n        }\n      } catch (Exception e) {\n        if (!checkPathAccess(p, FsAction.WRITE_EXECUTE, \"delete\")) {\n          return superGroupFileSystem.delete(p, recursive);\n        }\n      }\n    }\n    statistics.incrementWriteOps(1);\n    if (recursive)\n      return rmr(p);\n    int r = lib.jfs_delete(Thread.currentThread().getId(), handle, normalizePath(p));\n    if (r == ENOENT) {\n      return false;\n    }\n    if (r < 0) {\n      throw error(r, p);\n    }\n    return true;\n  }\n\n  @Override\n  public ContentSummary getContentSummary(Path f) throws IOException {\n    if (needCheckPermission() && !checkPathAccess(f, FsAction.READ_EXECUTE, \"getContentSummary\")) {\n      return superGroupFileSystem.getContentSummary(f);\n    }\n    statistics.incrementReadOps(1);\n    String path = normalizePath(f);\n    Pointer buf = Memory.allocate(Runtime.getRuntime(lib), 40);\n    int r = lib.jfs_summary(Thread.currentThread().getId(), handle, path, buf);\n    if (r < 0) {\n      throw error(r, f);\n    }\n    long size = buf.getLongLong(0);\n    long files = buf.getLongLong(8);","sourceCodeStart":1713,"sourceCodeEnd":1749,"githubUrl":"https://github.com/juicedata/juicefs/blob/c9a67b23e8e08ec23ec331aa6f1675e2319e921c/sdk/java/src/main/java/io/juicefs/JuiceFileSystemImpl.java#L1713-L1749","documentation":"The Java SDK's delete() calls the native jfs_delete; any negative errno other than ENOENT is converted by error(errno, p) into the matching Hadoop IOException subclass (PathPermissionException for EPERM, FileNotFoundException for ENOENT, AccessControlException for EACCES, etc.). The thrown exception carries 'errno: <n> <path>'. This is the standard error-mapping surface for delete failures.","triggerScenarios":"`fs.delete(path, recursive)` where the native layer returns EPERM/EACCES (no write permission on parent), EINVAL, ENOTEMPTY (non-recursive delete of non-empty dir), EROFS, etc.","commonSituations":"Deleting a file owned by another user without permissions on the parent directory; deleting a non-empty directory with recursive=false; operating on a read-only mounted volume; path does not exist (handled as 'return false' for ENOENT, not thrown).","solutions":["Check parent-directory write permission for the current Hadoop user (owner/group/mode) before delete","Use recursive=true for non-empty directories to avoid ENOTEMPTY","Verify the path string and that the volume is not mounted read-only","Catch and inspect the specific Hadoop exception subclass to branch on permission vs not-found"],"exampleFix":"// before\nfs.delete(path, false); // may throw PathIsNotEmptyDirectoryException\n// after\nif (fs.exists(path)) {\n  fs.delete(path, true); // recursive\n}","handlingStrategy":"try-catch","validationCode":"// Java\nPath parent = path.getParent();\nFsPermission perm = fs.getFileStatus(parent).getPermission();\nboolean canWrite = perm.applyUMask(FsPermission.getUMask(null)).implies(FsAction.WRITE);\nif (!canWrite) throw new AccessControlException(\"no write on \" + parent);","typeGuard":null,"tryCatchPattern":"try {\n  fs.delete(p, recursive);\n} catch (PathPermissionException | AccessControlException e) {\n  LOG.warn(\"delete denied: {}\", e.getMessage());\n} catch (FileNotFoundException e) {\n  // already gone — treat as success\n}","preventionTips":["Pre-check parent directory write permission","Use recursive=true for directories","Handle ENOENT as idempotent success"],"tags":["hadoop","jni","file-delete","errno"],"backgroundTag":"permission-denied","analyzedSha":"c9a67b23e8e08ec23ec331aa6f1675e2319e921c","analyzedAt":"2026-09-06T17:55:48.476Z","contentChangedAt":"2026-09-06T17:55:48.476Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}