{"record":{"id":"718c76197087b704","repo":"asLody/VirtualApp","slug":"key-is-null","errorCode":null,"errorMessage":"key is null","messagePattern":"key 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":361,"sourceCode":"\n    @Override\n    public void setAuthToken(int userId, Account account, String authTokenType, String authToken) {\n        if (account == null) throw new IllegalArgumentException(\"account is null\");\n        if (authTokenType == null) throw new IllegalArgumentException(\"authTokenType is null\");\n        synchronized (accountsByUserId) {\n            VAccount vAccount = getAccount(userId, account);\n            if (vAccount != null) {\n                // FIXME: cancelNotification\n                vAccount.authTokens.put(authTokenType, authToken);\n                this.saveAllAccounts();\n            }\n        }\n    }\n\n\n    @Override\n    public void setUserData(int userId, Account account, String key, String value) {\n        if (key == null) throw new IllegalArgumentException(\"key is null\");\n        if (account == null) throw new IllegalArgumentException(\"account is null\");\n        VAccount vAccount = getAccount(userId, account);\n        if (vAccount != null) {\n            synchronized (accountsByUserId) {\n                vAccount.userDatas.put(key, value);\n                saveAllAccounts();\n            }\n        }\n    }\n\n\n    @Override\n    public void hasFeatures(int userId, IAccountManagerResponse response,\n                            final Account account, final String[] features) {\n        if (response == null) throw new IllegalArgumentException(\"response is null\");\n        if (account == null) throw new IllegalArgumentException(\"account is null\");\n        if (features == null) throw new IllegalArgumentException(\"features is null\");\n        AuthenticatorInfo info = this.getAuthenticatorInfo(account.type);","sourceCodeStart":343,"sourceCodeEnd":379,"githubUrl":"https://github.com/asLody/VirtualApp/blob/666fefcb5d3f39cc944001c3457c38ffd6544c87/VirtualApp/lib/src/main/java/com/lody/virtual/server/accounts/VAccountManagerService.java#L343-L379","documentation":"setUserData(userId, account, key, value) throws IllegalArgumentException('key is null') as its first guard. User data is stored in a per-account map keyed by 'key', so a null key is invalid before any account resolution happens. Android's AccountManager has the same requirement for setUserData.","triggerScenarios":"Calling setUserData with a null key — typically a userdata constant read from config/resources that resolved to null, or a variable holding the key never initialized.","commonSituations":"Storing profile flags (e.g. 'user_id', 'sync_enabled') where the constant string was mistyped; resources/string lookups returning null; reflection-driven key names missing at runtime.","solutions":["Pass a non-null key string literal or constant","Validate any dynamically-loaded key (resources/config) before calling","Check key non-null before account handling since key is validated first"],"exampleFix":"// before\nmanager.setUserData(userId, account, key, value);\n// after\nif (key == null || account == null) {\n    Log.w(TAG, \"setUserData skipped: key/account null\");\n    return;\n}\nmanager.setUserData(userId, account, key, value);","handlingStrategy":"validation","validationCode":"if (key == null || key.isEmpty()) { throw new IllegalStateException(\"userdata key required\"); }","typeGuard":"boolean canSetUserData(String key, Account a) { return key != null && !key.isEmpty() && a != null; }","tryCatchPattern":null,"preventionTips":["Keep userdata keys as named constants in one place","Validate keys loaded from resources/config (getString can return null)","Validate key before account since the service checks key first"],"tags":["android","accounts","userdata","null-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"}