{"record":{"id":"d01393455b201fdd","repo":"MuntashirAkon/AppManager","slug":"locking-a-remote-file-is-not-supported","errorCode":null,"errorMessage":"Locking a remote file is not supported!","messagePattern":"Locking a remote file is not supported!","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"libcore/io/src/main/java/io/github/muntashirakon/io/RemoteFileChannel.java","lineNumber":361,"sourceCode":"    @Override\n    protected void implCloseChannel() {\n        try { fs.close(handle); } catch (RemoteException ignored) {}\n        synchronized (fdLock) {\n            try { Os.close(read); } catch (ErrnoException ignored) {}\n            try { Os.close(write); } catch (ErrnoException ignored) {}\n        }\n    }\n\n    // Unsupported operations\n\n    @Override\n    public MappedByteBuffer map(MapMode mode, long position, long size) {\n        throw new UnsupportedOperationException(\"Memory mapping a remote file is not supported!\");\n    }\n\n    @Override\n    public FileLock lock(long position, long size, boolean shared) {\n        throw new UnsupportedOperationException(\"Locking a remote file is not supported!\");\n    }\n\n    @Override\n    public FileLock tryLock(long position, long size, boolean shared) {\n        throw new UnsupportedOperationException(\"Locking a remote file is not supported!\");\n    }\n}","sourceCodeStart":343,"sourceCodeEnd":368,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/libcore/io/src/main/java/io/github/muntashirakon/io/RemoteFileChannel.java#L343-L368","documentation":"RemoteFileChannel extends FileChannel to wrap a remote file, but POSIX-style file locking cannot be implemented over the remote-file transport, so lock() unconditionally throws UnsupportedOperationException. The library deliberately rejects the operation instead of silently misbehaving. Any blocking lock attempt on a remote file channel fails immediately.","triggerScenarios":"Calling FileChannel.lock(long,long,boolean) on a channel obtained for a remote file (e.g. via RemoteFile inputs), typically to coordinate exclusive access across processes.","commonSituations":"Code written for local files that uses lock() for atomic read-modify-write or to prevent concurrent modification, later run against a remote file path in App Manager's file abstraction.","solutions":["Remove the lock() call and use an application-level mutex/synchronization instead","Restrict locking code paths to local files only (check the file type before locking)","Use an alternative coordination mechanism such as a lock file on local storage"],"exampleFix":"// before\ntry (FileLock lck = channel.lock(0, Long.MAX_VALUE, false)) { ... }\n// after\nif (!(channel instanceof RemoteFileChannel)) {\n    try (FileLock lck = channel.lock(0, Long.MAX_VALUE, false)) { ... }\n} else {\n    // app-level synchronization\n}","handlingStrategy":"try-catch","validationCode":"boolean canLock = !(channel instanceof RemoteFileChannel);","typeGuard":"boolean isRemoteChannel(FileChannel ch) { return ch instanceof RemoteFileChannel; }","tryCatchPattern":"try {\n    channel.lock(0, Long.MAX_VALUE, false);\n} catch (UnsupportedOperationException e) {\n    // fall back to app-level synchronization\n}","preventionTips":["Check the concrete channel/file type before using FileChannel features","Never assume FileChannel subclasses support the full FileChannel API","Use app-level locks for cross-process coordination on remote files"],"tags":["java","file-channel","unsupported-operation"],"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"}