MuntashirAkon/AppManager · error · IllegalStateException
Could not create cache. Is this OS broken?
Error message
Could not create cache. Is this OS broken?
What it means
The private FileCache constructor creates <cache-path>/files on first use and throws IllegalStateException("Could not create cache. Is this OS broken?") if mkdirs() fails. It assumes cache-directory creation can only fail in a fundamentally broken environment, hiding the real cause (storage full, permission denied, path unavailable).
Source
Thrown at app/src/main/java/io/github/muntashirakon/AppManager/self/filecache/FileCache.java:54
private final File mCacheDir;
private final Map<Path, File> mFileCacheMap = new HashMap<>();
private final Set<File> mFileCache = new HashSet<>();
private final Set<File> mDirectoryCache = new HashSet<>();
private final boolean mSessionOnly;
private boolean mClosed = false;
public FileCache() {
this(true);
}
private FileCache(boolean sessionOnly) {
mSessionOnly = sessionOnly;
mCacheDir = new File(FileUtils.getCachePath(), "files");
if (!mCacheDir.exists()) {
if (!mCacheDir.mkdirs()) {
throw new IllegalStateException("Could not create cache. Is this OS broken?");
}
}
}
@Override
public void close() {
mClosed = true;
if (mSessionOnly) {
deleteAll();
}
}
@Override
protected void finalize() {
if (!mClosed) {
close();
}
}View on GitHub (pinned to 0152f468fc)
Solutions
- Check free storage space; free space or clear the app cache so the directory can be recreated.
- Log FileUtils.getCachePath() when mkdirs fails to identify the real cause (the boolean return hides errno).
- Catch IllegalStateException at cache-consumer call sites and disable caching features gracefully.
- Restart the app/runtime if the cache path is only temporarily unavailable.
- On restricted profiles, ensure the app's cache directories are accessible or fall back to internal cache.
Example fix
// before
if (!mCacheDir.exists()) {
if (!mCacheDir.mkdirs()) {
throw new IllegalStateException("Could not create cache. Is this OS broken?");
}
}
// after
if (!mCacheDir.exists() && !mCacheDir.mkdirs()) {
File fallback = new File(ContextUtils.getContext().getCacheDir(), "files");
if (fallback.equals(mCacheDir) || !fallback.mkdirs()) {
throw new IllegalStateException("Could not create cache at " + mCacheDir);
}
mCacheDir = fallback;
} Defensive patterns
Strategy: try-catch
Validate before calling
File cacheDir = new File(FileUtils.getCachePath(), "files");
boolean ok = cacheDir.isDirectory()
|| (cacheDir.getParentFile() != null
&& cacheDir.getParentFile().canWrite()
&& cacheDir.mkdirs());
if (!ok) {
// storage full or unwritable: disable cache-dependent features first
} Try / catch
try {
FileCache cache = FileCache.getInstance();
// use cache
} catch (IllegalStateException e) {
// cache unavailable: skip caching, free storage space, or clear app cache
} Prevention
- Monitor free disk space before performing cache-heavy operations.
- Clear stale cache entries regularly so cache-dir recreation is rarely needed.
- Test on restricted/work profiles and low-storage devices.
- Log FileUtils.getCachePath() on failure to distinguish full storage vs permission issues.
When it happens
Trigger: Instantiating FileCache when the cache path returned by FileUtils.getCachePath() cannot be created: storage full, unwritable parent, cache dir unavailable in restricted users/profiles, or emulated-storage failures.
Common situations: Device storage completely full, app cache deleted with unwritable parent, multi-user/work/restricted profiles denying cache access, FUSE/emulated-storage failures on some ROMs, cloned apps in isolated profiles.
Understand the failure class
Background: mkdir permission denied (EACCES): failed to create directory errors explained — this error's family across 32 libraries.
Related errors
- Couldn't find any writable Obb dir
- Could not delete the selected backups
- Could not create package staging directory
- Could not create staging files
- Failed to access properties of the KeyStore folder.
AI-assisted analysis of MuntashirAkon/AppManager@0152f468fc (2026-09-12).
Data as JSON: /api/errors/072d5d57c00d2d1c.
Report an issue: GitHub.