{"record":{"id":"61b50831c3faf384","repo":"beemdevelopment/Aegis","slug":"openoutputstream-returned-null-61b508","errorCode":null,"errorMessage":"openOutputStream returned null","messagePattern":"openOutputStream returned null","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"app/src/main/java/com/beemdevelopment/aegis/vault/VaultBackupManager.java","lineNumber":96,"sourceCode":"            createBackup(tempFile, uri, versionsToKeep);\n        } else {\n            throw new VaultRepositoryException(\"Invalid backups versioning strategy\");\n        }\n    }\n\n    private void createBackup(File tempFile, Uri fileUri)\n            throws VaultRepositoryException, VaultBackupPermissionException {\n        Log.i(TAG, String.format(\"Creating backup at %s\", fileUri));\n        try {\n            if (!hasPermissionsAt(fileUri)) {\n                throw new VaultBackupPermissionException(\"No persisted URI permissions\");\n            }\n            ContentResolver resolver = _context.getContentResolver();\n            try (FileInputStream inStream = new FileInputStream(tempFile);\n                 OutputStream outStream = resolver.openOutputStream(fileUri, \"wt\")\n            ) {\n                if (outStream == null) {\n                    throw new IOException(\"openOutputStream returned null\");\n                }\n                IOUtils.copy(inStream, outStream);\n            } catch (IOException exception) {\n                throw new VaultRepositoryException(exception);\n            }\n        } catch (VaultRepositoryException | VaultBackupPermissionException exception) {\n            Log.e(TAG, String.format(\"Unable to create backup: %s\", exception));\n            throw exception;\n        } finally {\n            tempFile.delete();\n        }\n    }\n\n    private void createBackup(File tempFile, Uri dirUri, int versionsToKeep)\n            throws VaultRepositoryException, VaultBackupPermissionException {\n        FileInfo fileInfo = new FileInfo(FILENAME_PREFIX);\n        DocumentFile dir = DocumentFile.fromTreeUri(_context, dirUri);\n","sourceCodeStart":78,"sourceCodeEnd":114,"githubUrl":"https://github.com/beemdevelopment/Aegis/blob/d6f4e5925a97e4e91593f1542085eae03432a759/app/src/main/java/com/beemdevelopment/aegis/vault/VaultBackupManager.java#L78-L114","documentation":"Guard in VaultBackupManager.createBackup(File, Uri): thrown as VaultRepositoryException when ContentResolver.openOutputStream(fileUri) returns null, meaning the provider accepted the URI but cannot supply a writable stream (destination removed or locked). The backup attempt fails and scheduleBackup records the error in Preferences.BackupResult for the UI.","triggerScenarios":"Thrown at app/src/main/java/com/beemdevelopment/aegis/vault/VaultBackupManager.java:96 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Null-check the OutputStream returned by ContentResolver.openOutputStream(fileUri, \"wt\") and throw VaultRepositoryException naming the backup Uri","Verify hasPermissionsAt(fileUri) passed and the Uri still resolves (query it) before opening the output stream","Retry once with mode \"w\" if openOutputStream returns null for \"wt\", since some providers do not support truncation mode","Catch SecurityException from openOutputStream and convert it to VaultBackupPermissionException so the user is prompted to re-grant access"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"d6f4e5925a97e4e91593f1542085eae03432a759","analyzedAt":"2026-09-08T00:46:31.111Z","contentChangedAt":"2026-09-08T00:46:31.111Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}