{"record":{"id":"408fff741ccab740","repo":"CarGuo/GSYVideoPlayer","slug":"error-opening-s-as-disc-cache","errorCode":null,"errorMessage":"Error opening %s as disc cache","messagePattern":"Error opening (.+?) as disc cache","errorType":"exception","errorClass":"ProxyCacheException","httpStatus":null,"severity":"error","filePath":"gsyVideoPlayer-proxy_cache/src/main/java/com/danikula/videocache/file/FileCache.java","lineNumber":105,"sourceCode":"    @Override\n    public synchronized void complete() throws ProxyCacheException {\n        if (isCompleted()) {\n            return;\n        }\n\n        close();\n        String fileName = file.getName().substring(0, file.getName().length() - TEMP_POSTFIX.length());\n        File completedFile = new File(file.getParentFile(), fileName);\n        boolean renamed = file.renameTo(completedFile);\n        if (!renamed) {\n            throw new ProxyCacheException(\"Error renaming file \" + file + \" to \" + completedFile + \" for completion!\");\n        }\n        file = completedFile;\n        try {\n            dataFile = new RandomAccessFile(file, \"r\");\n            diskUsage.touch(file);\n        } catch (IOException e) {\n            throw new ProxyCacheException(\"Error opening \" + file + \" as disc cache\", e);\n        }\n    }\n\n    @Override\n    public synchronized boolean isCompleted() {\n        return !isTempFile(file);\n    }\n\n    /**\n     * Returns file to be used fo caching. It may as original file passed in constructor as some temp file for not completed cache.\n     *\n     * @return file for caching.\n     */\n    public File getFile() {\n        return file;\n    }\n\n    private boolean isTempFile(File file) {","sourceCodeStart":87,"sourceCodeEnd":123,"githubUrl":"https://github.com/CarGuo/GSYVideoPlayer/blob/e5d74d3aa9d7fb1393a879e33ee380f8f41354f1/gsyVideoPlayer-proxy_cache/src/main/java/com/danikula/videocache/file/FileCache.java#L87-L123","documentation":"Files.makeDir validates the cache directory: if a path exists but is a regular file (not a directory), it throws IOException('File <path> is not directory!'). This fires during FileCache construction when the configured cache root collides with an existing file of the same name.","triggerScenarios":"cacheDirectory passed to HttpProxyCacheServer.Builder points at a path where a file already exists - e.g. the developer pointed the cache dir at a path previously used as a file, or storage-cleaner tools replaced the dir entry, or the dir was configured after a file with that exact name was written.","commonSituations":"Copy-paste cache path mistakes (using a file path instead of dir); persisted user-configurable cache location that once held a file; restoring app data where directory was restored as file (some backup tools do this).","solutions":["Delete the conflicting file or choose a different directory name for the cache root","Always construct the cache dir via new File(context.getCacheDir(), \"proxy_cache\") which cannot collide","At startup, validate the configured path: if exists && !isDirectory, move/delete it before building the proxy"],"exampleFix":"// before\nFile cacheDir = new File(getExternalFilesDir(null), \"video.cache\"); // 'video.cache' may exist as a file\n\n// after\nFile cacheDir = new File(context.getCacheDir(), \"video_proxy_cache\");\nif (cacheDir.exists() && !cacheDir.isDirectory()) cacheDir.delete();","handlingStrategy":"validation","validationCode":"File cacheDir = new File(context.getCacheDir(), \"proxy\");\nif (cacheDir.exists() && !cacheDir.isDirectory()) {\n    cacheDir.delete(); // remove blocking file before building proxy\n}\ncacheDir.mkdirs();","typeGuard":"boolean isUsableCacheDir = !cacheDir.exists() || cacheDir.isDirectory();","tryCatchPattern":"catch (ProxyCacheException e) {\n    if (String.valueOf(e.getMessage()).contains(\"is not directory\")) {\n        blockingPath.delete(); // then rebuild HttpProxyCacheServer\n    } else throw e;\n}","preventionTips":["Build cache paths from getCacheDir()/getExternalCacheDir() subdirs","Validate configured cache paths at startup","Never point the cache dir at a path that previously stored a file"],"tags":["filesystem","configuration","storage","proxy-cache"],"backgroundTag":null,"analyzedSha":"e5d74d3aa9d7fb1393a879e33ee380f8f41354f1","analyzedAt":"2026-08-14T11:56:11.997Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}