{"record":{"id":"401556a5d49fa18c","repo":"MuntashirAkon/AppManager","slug":"memory-mapping-a-remote-file-is-not-supported","errorCode":null,"errorMessage":"Memory mapping a remote file is not supported!","messagePattern":"Memory mapping a remote file is not supported!","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"warning","filePath":"libcore/io/src/main/java/io/github/muntashirakon/io/RemoteFileChannel.java","lineNumber":356,"sourceCode":"            throw new IllegalArgumentException(\"Negative position\");\n        ensureOpen();\n        return write0(src, position);\n    }\n\n    @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":338,"sourceCodeEnd":368,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/libcore/io/src/main/java/io/github/muntashirakon/io/RemoteFileChannel.java#L338-L368","documentation":"RemoteFileChannel.map(mode, position, size) always throws UnsupportedOperationException: mmap() is a local process-address-space operation and cannot be performed on a file that lives in a remote process via Binder IPC. The channel deliberately rejects the call instead of emulating it.","triggerScenarios":"Calling map() on any RemoteFileChannel — always throws, regardless of mode, position, or size.","commonSituations":"Code paths shared between local FileChannel and RemoteFileChannel (e.g. parsing file formats via MappedByteBuffer); optimization attempts to avoid read() round-trips; libraries that internally mmap inputs.","solutions":["Replace map() with positional read()/write() loops over the same region.","If mmap is essential, copy the remote file locally first and map the local FileChannel.","Branch on channel type in shared code paths and use a buffer-based fallback for remote channels.","Wrap map-dependent consumers behind an abstraction that accepts a readable channel instead of a MappedByteBuffer."],"exampleFix":"// before\nMappedByteBuffer buf = remoteChannel.map(MapMode.READ_ONLY, 0, remoteChannel.size());\n// after\nByteBuffer buf = ByteBuffer.allocate((int) remoteChannel.size());\nremoteChannel.read(buf, 0);\nbuf.flip();","handlingStrategy":"fallback","validationCode":"if (channel instanceof RemoteFileChannel) {\n    useBufferedReadWrite(channel); // never call map()\n}","typeGuard":"boolean supportsMmap(FileChannel ch) {\n    return !(ch instanceof RemoteFileChannel);\n}","tryCatchPattern":"try {\n    return channel.map(mode, position, size);\n} catch (UnsupportedOperationException e) {\n    return readIntoBuffer(channel, position, size); // fallback\n}","preventionTips":["Design consumers around ReadableByteChannel, not MappedByteBuffer.","Copy remote files locally when mmap is truly required.","Keep RemoteFileChannel-specific code paths separate from mmap-based local paths."],"tags":["unsupported-operation","memory-mapping","file-channel"],"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"}