{"record":{"id":"353add3d9b04eec3","repo":"MuntashirAkon/AppManager","slug":"could-not-create-cache-is-this-os-broken-imagefilecache","errorCode":null,"errorMessage":"Could not create cache. Is this OS broken?","messagePattern":"Could not create cache\\. Is this OS broken\\?","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"app/src/main/java/io/github/muntashirakon/AppManager/self/imagecache/ImageFileCache.java","lineNumber":33,"sourceCode":"import java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\n\nimport io.github.muntashirakon.AppManager.logs.Log;\nimport io.github.muntashirakon.AppManager.utils.FileUtils;\nimport io.github.muntashirakon.AppManager.utils.UIUtils;\nimport io.github.muntashirakon.io.IoUtils;\n\nclass ImageFileCache {\n    private static final long sLastModifiedDate = System.currentTimeMillis() - 604_800_000;\n\n    private final File mCacheDir;\n\n    public ImageFileCache() {\n        mCacheDir = new File(FileUtils.getCachePath(), \"images\");\n        if (!mCacheDir.exists()) {\n            if (!mCacheDir.mkdirs()) {\n                throw new IllegalStateException(\"Could not create cache. Is this OS broken?\");\n            }\n        }\n    }\n\n    public void putImage(@NonNull String name, @NonNull InputStream inputStream) throws IOException {\n        File iconFile = getImageFile(name);\n        try (OutputStream os = new FileOutputStream(iconFile)) {\n            IoUtils.copy(inputStream, os);\n        }\n    }\n\n    public void putImage(@NonNull String name, @NonNull Drawable drawable) throws IOException {\n        putImage(name, UIUtils.getBitmapFromDrawable(drawable));\n    }\n\n    public void putImage(@NonNull String name, @NonNull Bitmap bitmap) throws IOException {\n        File iconFile = getImageFile(name);\n        try (OutputStream os = new FileOutputStream(iconFile)) {","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/app/src/main/java/io/github/muntashirakon/AppManager/self/imagecache/ImageFileCache.java#L15-L51","documentation":"ImageFileCache's constructor creates the cache directory <cache>/images via mkdirs() and throws IllegalStateException if creation fails. Since File.mkdirs() only fails on real OS-level problems (no permissions, filesystem full/read-only), the message rhetorically asks if the OS is broken. It effectively signals an unrecoverable environment failure at init time.","triggerScenarios":"Constructing ImageFileCache when Context.getCacheDir()/getCachePath() cannot be created or written: read-only filesystem, missing storage permissions, parent path inaccessible, or cache path malformed.","commonSituations":"Device storage full or mounted read-only (e.g. after USB access on some devices); running on a locked-down/emulated environment; custom ROM with broken cache-dir permissions.","solutions":["Check available storage and free space on the device","Verify Environment/Context cache path is writable before constructing ImageFileCache","Reboot or clear app data to reset cache directory permissions","Catch the IllegalStateException and disable image caching as a fallback"],"exampleFix":"// before\nImageFileCache cache = new ImageFileCache();\n// after\nImageFileCache cache;\ntry {\n    cache = new ImageFileCache();\n} catch (IllegalStateException e) {\n    cache = null; // proceed without image caching\n}","handlingStrategy":"try-catch","validationCode":"File cacheDir = new File(FileUtils.getCachePath(), \"images\");\nif (!cacheDir.isDirectory() && !cacheDir.mkdirs()) {\n    throw new IllegalStateException(\"Cache dir not creatable: \" + cacheDir);\n}","typeGuard":null,"tryCatchPattern":"try {\n    ImageFileCache cache = new ImageFileCache();\n} catch (IllegalStateException e) {\n    // disable icon caching / show degraded mode\n}","preventionTips":["Verify cache path exists and is writable before first use","Monitor device free space and degrade gracefully when low","Catch constructor exceptions at app startup and disable caching instead of crashing","Treat cache dirs as optional: always guard writes to them"],"tags":["io","filesystem","android","initialization"],"backgroundTag":"module-init-failed","analyzedSha":"0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5","analyzedAt":"2026-09-12T14:03:37.243Z","contentChangedAt":"2026-09-12T14:03:37.243Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}