{"record":{"id":"a64f0e0f41298f19","repo":"asLody/VirtualApp","slug":"account-is-null","errorCode":null,"errorMessage":"account is null","messagePattern":"account is null","errorType":"exception","errorClass":"java.lang.IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"VirtualApp/lib/src/main/java/com/lody/virtual/server/accounts/VAccountManagerService.java","lineNumber":154,"sourceCode":"            return;\n        }\n\n        if (features == null || features.length == 0) {\n            Bundle bundle = new Bundle();\n            bundle.putParcelableArray(AccountManager.KEY_ACCOUNTS, getAccounts(userId, type));\n            try {\n                response.onResult(bundle);\n            } catch (RemoteException e) {\n                e.printStackTrace();\n            }\n        } else {\n            new GetAccountsByTypeAndFeatureSession(response, userId, info, features).bind();\n        }\n    }\n\n    @Override\n    public final String getPreviousName(int userId, Account account) {\n        if (account == null) throw new IllegalArgumentException(\"account is null\");\n        synchronized (accountsByUserId) {\n            String previousName = null;\n            VAccount vAccount = getAccount(userId, account);\n            if (vAccount != null) {\n                previousName = vAccount.previousName;\n            }\n            return previousName;\n        }\n    }\n\n\n    @Override\n    public Account[] getAccounts(int userId, String type) {\n        List<Account> accountList = getAccountList(userId, type);\n        return accountList.toArray(new Account[accountList.size()]);\n    }\n\n","sourceCodeStart":136,"sourceCodeEnd":172,"githubUrl":"https://github.com/asLody/VirtualApp/blob/666fefcb5d3f39cc944001c3457c38ffd6544c87/VirtualApp/lib/src/main/java/com/lody/virtual/server/accounts/VAccountManagerService.java#L136-L172","documentation":"getPreviousName(userId, account) throws IllegalArgumentException('account is null') as a fail-fast guard when the caller passes a null Account. VirtualApp's VAccountManagerService mirrors Android's AccountManager contract, which requires a non-null account to look up the previous name. The throw happens before any account lookup or locking.","triggerScenarios":"Calling getPreviousName with a null Account object, typically because an earlier AccountManager call (e.g. getAccounts, getAccountsByTypeAndFeatures) returned an array/entry the caller assumed was non-null, or a variable holding the account was never initialized.","commonSituations":"App code iterating accounts from a callback that can deliver empty/null results; refactors where an Account field is assigned null on failure; testing code that calls the service directly without constructing an Account.","solutions":["Ensure the Account passed to getPreviousName is non-null before calling (check for null and skip/return)","Verify the code that produced the Account (getAccounts / getAccountsByTypeAndFeatures callback) and handle empty results instead of propagating null","Catch IllegalArgumentException around the call as a last resort and treat it as 'no previous name'"],"exampleFix":"// before\nString prev = manager.getPreviousName(userId, account);\n// after\nif (account != null) {\n    String prev = manager.getPreviousName(userId, account);\n} else {\n    String prev = null; // handle missing account\n}","handlingStrategy":"validation","validationCode":"if (account == null) { throw new IllegalStateException(\"Cannot getPreviousName: account is null\"); }","typeGuard":"boolean isValidAccount(Account a) { return a != null && a.type != null && a.name != null; }","tryCatchPattern":null,"preventionTips":["Null-check accounts returned from AccountManager lookups before use","Never cache Account references across sign-out flows without re-validating","Treat null account as 'no data' in UI/reporting layers rather than passing it down"],"tags":["android","accounts","null-argument","illegal-argument"],"backgroundTag":"null-argument","analyzedSha":"666fefcb5d3f39cc944001c3457c38ffd6544c87","analyzedAt":"2026-09-09T11:09:01.694Z","contentChangedAt":"2026-09-09T11:09:01.694Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}