{"record":{"id":"0aa3203d6a94fc1e","repo":"languagetool-org/languagetool","slug":"no-user-found-for-given-username-and-given-api","errorCode":null,"errorMessage":"No user found for given username '' and given api key","messagePattern":"No user found for given username '' and given api key","errorType":"http","errorClass":"IllegalArgumentException","httpStatus":403,"severity":"error","filePath":"languagetool-server/src/main/java/org/languagetool/server/DatabaseAccessOpenSource.java","lineNumber":229,"sourceCode":"    if (sqlSessionFactory == null) {\n      throw new AuthException(\"This is the endpoint for the basic version of LanguageTool. \" +\n        \"When using 'username' and 'apiKey' to access the premium version, use api.languagetoolplus.com instead.\");\n    }\n    try {\n      Long value = dbLoggingCache.get(String.format(\"user_%s_%s\", username, apiKey), () -> {\n        try (SqlSession session = sqlSessionFactory.openSession()) {\n          Map<Object, Object> map = new HashMap<>();\n          map.put(\"username\", username);\n          map.put(\"apiKey\", apiKey);\n          Long id = session.selectOne(\"org.languagetool.server.UserDictMapper.getUserIdByApiKey\", map);\n          if (id == null) {\n            return -1L;\n          }\n          return id;\n        }\n      });\n      if (value == -1) {\n        throw new IllegalArgumentException(\"No user found for given username '\" + username + \"' and given api key\");\n      } else {\n        return value;\n      }\n    } catch (ExecutionException e) {\n      throw new IllegalStateException(\"Could not fetch given user '\" + username + \"' from cache\", e);\n    }\n  }\n\n  boolean deleteWord(String word, Long userId) {\n    if (sqlSessionFactory == null) {\n      return false;\n    }\n    try (SqlSession session = sqlSessionFactory.openSession(true)) {\n      Map<Object, Object> map = new HashMap<>();\n      map.put(\"word\", word);\n      map.put(\"userId\", userId);\n      int count = session.delete(\"org.languagetool.server.UserDictMapper.selectWord\", map);\n      if (count == 0) {","sourceCodeStart":211,"sourceCodeEnd":247,"githubUrl":"https://github.com/languagetool-org/languagetool/blob/2e990059ce67d5e2a0f7f7ca5d31160c6709df4b/languagetool-server/src/main/java/org/languagetool/server/DatabaseAccessOpenSource.java#L211-L247","documentation":"After querying the database via dbLoggingCache, getUserId treats a sentinel result of -1 as 'no matching user' and throws IllegalArgumentException with the username embedded in the message. The credentials were syntactically valid, but no user row matches the given username and API key.","triggerScenarios":"Calling getUserId (or endpoints using it) with a username/apiKey pair that does not exist in the configured database; the SQL lookup returns no/invalid ID and the loader returns -1L.","commonSituations":"Typo in username or apiKey; key regenerated/revoked server-side while the client caches the old one; client pointed at a server whose database hosts a different user base; stale credentials after account changes.","solutions":["Verify the username and apiKey are correct and current; regenerate the API key if needed and update the client.","Confirm the client is pointed at the server/endpoint whose database actually contains this user (premium vs self-hosted user store).","Handle the IllegalArgumentException in the client and prompt the user to re-enter credentials instead of retrying automatically."],"exampleFix":"// before\nlookup(\"bob\", \"old-revoked-key\"); // IllegalArgumentException: No user found for given username 'bob'...\n// after\nString key = fetchFreshApiKeyFromAccountPage();\nif (key != null && !key.isBlank()) lookup(\"bob\", key);","handlingStrategy":"try-catch","validationCode":"if (username == null || apiKey == null || username.isBlank() || apiKey.isBlank()) {\n  throw new IllegalArgumentException(\"username and apiKey required\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  Long userId = db.getUserId(username, apiKey);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage().contains(\"No user found\")) {\n    // invalidate stored credentials and prompt re-authentication\n  }\n}","preventionTips":["Keep client API keys in sync with server-side accounts; re-fetch after regeneration.","Confirm the server's database actually contains the user you authenticate as.","Never cache username/apiKey pairs indefinitely; handle re-auth on lookup failure."],"tags":["java","authentication","user-not-found","invalid-credentials"],"backgroundTag":"user-not-found","analyzedSha":"2e990059ce67d5e2a0f7f7ca5d31160c6709df4b","analyzedAt":"2026-09-06T09:20:17.015Z","contentChangedAt":"2026-09-06T09:20:17.015Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}