{"record":{"id":"0fdf07154ce45a51","repo":"CarGuo/GSYVideoPlayer","slug":"error-writing-d-bytes-to-s-from-buffer-with-size","errorCode":null,"errorMessage":"Error writing %d bytes to %s from buffer with size %d","messagePattern":"Error writing (.+?) bytes to (.+?) from buffer with size (.+?)","errorType":"exception","errorClass":"ProxyCacheException","httpStatus":null,"severity":"warning","filePath":"gsyVideoPlayer-proxy_cache/src/main/java/com/danikula/videocache/file/FileCache.java","lineNumber":73,"sourceCode":"            dataFile.seek(offset);\n            return dataFile.read(buffer, 0, length);\n        } catch (IOException e) {\n            String format = \"Error reading %d bytes with offset %d from file[%d bytes] to buffer[%d bytes]\";\n            throw new ProxyCacheException(String.format(format, length, offset, available(), buffer.length), e);\n        }\n    }\n\n    @Override\n    public synchronized void append(byte[] data, int length) throws ProxyCacheException {\n        try {\n            if (isCompleted()) {\n                throw new ProxyCacheException(\"Error append cache: cache file \" + file + \" is completed!\");\n            }\n            dataFile.seek(available());\n            dataFile.write(data, 0, length);\n        } catch (IOException e) {\n            String format = \"Error writing %d bytes to %s from buffer with size %d\";\n            throw new ProxyCacheException(String.format(format, length, dataFile, data.length), e);\n        }\n    }\n\n    @Override\n    public synchronized void close() throws ProxyCacheException {\n        try {\n            dataFile.close();\n            diskUsage.touch(file);\n        } catch (IOException e) {\n            throw new ProxyCacheException(\"Error closing file \" + file, e);\n        }\n    }\n\n    @Override\n    public synchronized void complete() throws ProxyCacheException {\n        if (isCompleted()) {\n            return;\n        }","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/CarGuo/GSYVideoPlayer/blob/e5d74d3aa9d7fb1393a879e33ee380f8f41354f1/gsyVideoPlayer-proxy_cache/src/main/java/com/danikula/videocache/file/FileCache.java#L55-L91","documentation":"FileCache.close closes the RandomAccessFile and touches DiskUsage (updates last-modified for LRU). IOException from dataFile.close() is wrapped as 'Error closing file <path>'. Note close() is also called inside complete(), so this error can surface during completion as well as during release.","triggerScenarios":"Closing a RandomAccessFile whose fd is already invalid (file deleted by a cleaner/eviction underneath), or an IO error reported by the OS on close (NFS-ish storage, corrupted sdcard fs).","commonSituations":"Same family as errors 10/13: file removed mid-session, removable storage ejected, aggressive cache cleaners. Mostly seen as cleanup noise during player release rather than a functional failure.","solutions":["Keep cache files on internal storage not visible to cleaner apps","Treat close-time errors during release()/shutdown() as log-only - the session is ending anyway","Ensure eviction does not delete the file whose FileCache is still open (one proxy instance per dir)","If seen during complete(), check disk health / remount state of the storage holding the cache"],"exampleFix":"// before\npublic void release() { fileCache.close(); }\n\n// after - tolerate close failure during teardown\npublic void release() {\n    try { fileCache.close(); }\n    catch (ProxyCacheException e) { Log.w(TAG, \"cache close failed during release\", e); }\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { fileCache.close(); }\ncatch (ProxyCacheException e) {\n    if (String.valueOf(e.getMessage()).contains(\"Error closing file\")) {\n        Log.w(TAG, \"close failed during teardown\", e); // swallow during release\n    } else throw e;\n}","preventionTips":["Tolerate close failures during release/shutdown","Keep cache on internal storage not touched by cleaners","Investigate only if it fires outside teardown paths"],"tags":["io","cleanup","storage","proxy-cache"],"backgroundTag":null,"analyzedSha":"e5d74d3aa9d7fb1393a879e33ee380f8f41354f1","analyzedAt":"2026-08-14T11:56:11.997Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}