{"record":{"id":"a103d9593147a422","repo":"CarGuo/GSYVideoPlayer","slug":"file-s-is-not-directory","errorCode":null,"errorMessage":"File %s is not directory!","messagePattern":"File (.+?) is not directory!","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"gsyVideoPlayer-proxy_cache/src/main/java/com/danikula/videocache/file/Files.java","lineNumber":26,"sourceCode":"import java.util.Arrays;\nimport java.util.Collections;\nimport java.util.Comparator;\nimport java.util.Date;\nimport java.util.LinkedList;\nimport java.util.List;\n\n/**\n * Utils for work with files.\n *\n * @author Alexey Danilov (danikula@gmail.com).\n */\nclass Files {\n\n\n    static void makeDir(File directory) throws IOException {\n        if (directory.exists()) {\n            if (!directory.isDirectory()) {\n                throw new IOException(\"File \" + directory + \" is not directory!\");\n            }\n        } else {\n            boolean isCreated = directory.mkdirs();\n            if (!isCreated) {\n                throw new IOException(String.format(\"Directory %s can't be created\", directory.getAbsolutePath()));\n            }\n        }\n    }\n\n    static List<File> getLruListFiles(File directory) {\n        List<File> result = new LinkedList<>();\n        File[] files = directory.listFiles();\n        if (files != null) {\n            result = Arrays.asList(files);\n            Collections.sort(result, new LastModifiedComparator());\n        }\n        return result;\n    }","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/CarGuo/GSYVideoPlayer/blob/e5d74d3aa9d7fb1393a879e33ee380f8f41354f1/gsyVideoPlayer-proxy_cache/src/main/java/com/danikula/videocache/file/Files.java#L8-L44","documentation":"Files.makeDir's second failure mode: when the directory does not exist and mkdirs() returns false (or silently raced), it throws IOException('Directory <path> can't be created'). This is the generic 'cannot create cache directory' error surfaced through FileCache as ProxyCacheException.","triggerScenarios":"mkdirs() fails due to missing write permission on the parent (scoped storage, external storage unmounted), a parent path component exists as a file, or disk/fs errors. Called from FileCache's constructor before opening the RandomAccessFile.","commonSituations":"Hardcoded /sdcard/... paths on Android 10+ without legacy storage; WRITE_EXTERNAL_STORAGE missing on API <= 29; cache dir on ejected SD card; parent path segment occupied by a file; SELinux-denied vendor paths.","solutions":["Switch to context.getCacheDir() or context.getExternalCacheDir() subdirectories","Request WRITE_EXTERNAL_STORAGE (API <= 29) or use MANAGE_EXTERNAL_STORAGE/MediaStore appropriately","Check Environment.getExternalStorageState() before using any external path","Validate the whole parent chain is made of directories before building the proxy server"],"exampleFix":"// before\nFile cacheDir = new File(Environment.getExternalStorageDirectory(), \"videocache\");\nnew Builder(ctx).cacheDirectory(cacheDir).build();\n\n// after\nFile base = ctx.getExternalCacheDir();\nFile cacheDir = (base != null) ? new File(base, \"videocache\") : new File(ctx.getCacheDir(), \"videocache\");\nnew Builder(ctx).cacheDirectory(cacheDir).build();","handlingStrategy":"validation","validationCode":"File dir = ctx.getExternalCacheDir();\nif (dir == null || !Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {\n    dir = ctx.getCacheDir(); // internal fallback\n}\nFile cacheDir = new File(dir, \"proxy\");\nif (!cacheDir.exists() && !cacheDir.mkdirs() && !cacheDir.isDirectory()) {\n    throw new IOException(\"cannot prepare \" + cacheDir);\n}","typeGuard":null,"tryCatchPattern":"catch (ProxyCacheException e) {\n    if (String.valueOf(e.getMessage()).contains(\"is not directory\")) {\n        blockingPath.delete(); // remove the file occupying the dir path, then rebuild proxy\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","permissions","scoped-storage","storage","proxy-cache"],"backgroundTag":null,"analyzedSha":"e5d74d3aa9d7fb1393a879e33ee380f8f41354f1","analyzedAt":"2026-08-14T11:56:11.997Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}