{"record":{"id":"343872b39b48376b","repo":"MuntashirAkon/AppManager","slug":"content-provider-has-crashed","errorCode":null,"errorMessage":"Content provider has crashed.","messagePattern":"Content provider has crashed\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/src/main/java/io/github/muntashirakon/AppManager/rules/RulesExporter.java","lineNumber":45,"sourceCode":"    @Nullable\n    private List<String> mPackagesToExport;\n    @NonNull\n    private final List<RuleType> mTypesToExport;\n    @NonNull\n    private final int[] mUserIds;\n\n    public RulesExporter(@NonNull List<RuleType> typesToExport, @Nullable List<String> packagesToExport,\n                         @NonNull int[] userIds) {\n        mContext = ContextUtils.getContext();\n        mPackagesToExport = packagesToExport;\n        mTypesToExport = typesToExport;\n        mUserIds = userIds;\n    }\n\n    public void saveRules(Uri uri) throws IOException {\n        if (mPackagesToExport == null) mPackagesToExport = ComponentUtils.getAllPackagesWithRules(mContext);\n        try (OutputStream outputStream = mContext.getContentResolver().openOutputStream(uri)) {\n            if (outputStream == null) throw new IOException(\"Content provider has crashed.\");\n            for (String packageName: mPackagesToExport) {\n                for (int userHandle : mUserIds) {\n                    // Get a read-only instance\n                    try (ComponentsBlocker cb = ComponentsBlocker.getInstance(packageName, userHandle)) {\n                        ComponentUtils.storeRules(outputStream, cb.getAll(mTypesToExport), true);\n                    }\n                }\n            }\n        }\n    }\n}\n","sourceCodeStart":27,"sourceCodeEnd":57,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/app/src/main/java/io/github/muntashirakon/AppManager/rules/RulesExporter.java#L27-L57","documentation":"RulesExporter.saveRules opens an OutputStream on the destination Uri via ContentResolver.openOutputStream(). The contract allows openOutputStream to return null; when it does, the exporter throws IOException('Content provider has crashed.') because the content provider backing the Uri failed to supply a writable stream.","triggerScenarios":"Calling saveRules(uri) with a Uri whose provider returns null from openOutputStream: unwritable SAF target, provider crashed or was killed, or a Uri from a provider lacking write permission.","commonSituations":"Exporting rules to a cloud-storage or documents-provider location that disconnects mid-session; targeting a file:// Uri without proper grants; provider process death under memory pressure.","solutions":["Re-pick the export destination via SAF (ACTION_CREATE_DOCUMENT) to get a fresh writable Uri","Verify the Uri is writable (check provider grants, use FLAG_GRANT_WRITE_URI_PERMISSION)","Catch the IOException and surface a retry to the user instead of failing silently","Retry the export after confirming the storage provider is available"],"exampleFix":"// before\nexporter.saveRules(destinationUri);\n// after\ntry {\n    exporter.saveRules(destinationUri);\n} catch (IOException e) {\n    Toast.show(\"Export failed: destination provider unavailable, pick a new location\");\n}","handlingStrategy":"try-catch","validationCode":"try (OutputStream os = context.getContentResolver().openOutputStream(uri)) {\n    if (os == null) throw new IOException(\"Destination provider unavailable\");\n} // verify writability before starting the real export","typeGuard":null,"tryCatchPattern":"try {\n    exporter.saveRules(uri);\n} catch (IOException e) {\n    if (e.getMessage().contains(\"Content provider has crashed\")) {\n        promptRepickDestination();\n    } else throw e;\n}","preventionTips":["Use SAF document Uris with write grants, not raw file:// paths","Take persistable permissions when the user picks a destination","Check available storage and provider availability before exporting"],"tags":["android","content-provider","io","export"],"backgroundTag":"file-write-failed","analyzedSha":"0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5","analyzedAt":"2026-09-12T14:03:37.243Z","contentChangedAt":"2026-09-12T14:03:37.243Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}