{"record":{"id":"0030b5e0e27f9f69","repo":"MuntashirAkon/AppManager","slug":"deleteonexit-is-not-supported-in-remotefile","errorCode":null,"errorMessage":"deleteOnExit() is not supported in RemoteFile","messagePattern":"deleteOnExit\\(\\) is not supported in RemoteFile","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"warning","filePath":"libcore/io/src/main/java/io/github/muntashirakon/io/RemoteFile.java","lineNumber":312,"sourceCode":"        try {\n            return fs.createLink(getPath(), target, true).tryAndGet();\n        } catch (RemoteException e) {\n            throw new IOException(e);\n        }\n    }\n\n    @Override\n    public boolean delete() {\n        try {\n            return fs.delete(getPath());\n        } catch (RemoteException e) {\n            return false;\n        }\n    }\n\n    @Override\n    public void deleteOnExit() {\n        throw new UnsupportedOperationException(\"deleteOnExit() is not supported in RemoteFile\");\n    }\n\n    @Override\n    public String[] list() {\n        try {\n            StringParceledListSlice list = fs.list(getPath());\n            return list != null ? list.getList().toArray(new String[0]) : null;\n        } catch (RemoteException e) {\n            return null;\n        }\n    }\n\n    @Override\n    public boolean mkdir() {\n        try {\n            return fs.mkdir(getPath());\n        } catch (RemoteException e) {\n            return false;","sourceCodeStart":294,"sourceCodeEnd":330,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/libcore/io/src/main/java/io/github/muntashirakon/io/RemoteFile.java#L294-L330","documentation":"RemoteFile.deleteOnExit() unconditionally throws UnsupportedOperationException because delete-on-exit semantics require a JVM shutdown hook and an on-device File registry, which cannot be honored for files managed in a remote process. The library explicitly rejects the operation rather than silently ignoring it.","triggerScenarios":"Calling deleteOnExit() on any RemoteFile instance — always throws, regardless of path or state.","commonSituations":"Porting code written against java.io.File to RemoteFile and assuming API parity; temp-file cleanup utilities that call deleteOnExit generically on File-like abstractions.","solutions":["Replace deleteOnExit() with explicit delete() calls at a well-defined point in your flow.","Track remote temp files in your own list and clean them up on shutdown/exit of your component.","Guard generic cleanup code with instanceof checks so RemoteFile paths use explicit deletion.","If using a File-agnostic helper, use tryDelete-style wrappers that skip unsupported operations."],"exampleFix":"// before\nremoteFile.deleteOnExit();\n// after\nruntime.addShutdownHook(new Thread(() -> remoteFile.delete()));","handlingStrategy":"fallback","validationCode":"if (file instanceof RemoteFile) {\n    // use explicit delete(); deleteOnExit() is unsupported\n}","typeGuard":"boolean supportsDeleteOnExit(Object f) {\n    return !(f instanceof RemoteFile);\n}","tryCatchPattern":"try {\n    file.deleteOnExit();\n} catch (UnsupportedOperationException e) {\n    cleanupRegistry.add(file); // explicit delete later\n}","preventionTips":["Never assume java.io.File API parity on RemoteFile.","Centralize temp-file cleanup so RemoteFile paths get explicit delete().","Check the class javadoc for UnsupportedOperationException-declared methods before calling."],"tags":["unsupported-operation","java-io","android"],"backgroundTag":"unsupported-operation","analyzedSha":"0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5","analyzedAt":"2026-09-12T14:03:37.243Z","contentChangedAt":"2026-09-12T14:03:37.243Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}