languagetool-org/languagetool · error · IllegalArgumentException
No user found for given username '' and given api key
Error message
No user found for given username '' and given api key
What it means
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.
Source
Thrown at languagetool-server/src/main/java/org/languagetool/server/DatabaseAccessOpenSource.java:229
if (sqlSessionFactory == null) {
throw new AuthException("This is the endpoint for the basic version of LanguageTool. " +
"When using 'username' and 'apiKey' to access the premium version, use api.languagetoolplus.com instead.");
}
try {
Long value = dbLoggingCache.get(String.format("user_%s_%s", username, apiKey), () -> {
try (SqlSession session = sqlSessionFactory.openSession()) {
Map<Object, Object> map = new HashMap<>();
map.put("username", username);
map.put("apiKey", apiKey);
Long id = session.selectOne("org.languagetool.server.UserDictMapper.getUserIdByApiKey", map);
if (id == null) {
return -1L;
}
return id;
}
});
if (value == -1) {
throw new IllegalArgumentException("No user found for given username '" + username + "' and given api key");
} else {
return value;
}
} catch (ExecutionException e) {
throw new IllegalStateException("Could not fetch given user '" + username + "' from cache", e);
}
}
boolean deleteWord(String word, Long userId) {
if (sqlSessionFactory == null) {
return false;
}
try (SqlSession session = sqlSessionFactory.openSession(true)) {
Map<Object, Object> map = new HashMap<>();
map.put("word", word);
map.put("userId", userId);
int count = session.delete("org.languagetool.server.UserDictMapper.selectWord", map);
if (count == 0) {View on GitHub (pinned to 2e990059ce)
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.
Example fix
// before
lookup("bob", "old-revoked-key"); // IllegalArgumentException: No user found for given username 'bob'...
// after
String key = fetchFreshApiKeyFromAccountPage();
if (key != null && !key.isBlank()) lookup("bob", key); Defensive patterns
Strategy: try-catch
Validate before calling
if (username == null || apiKey == null || username.isBlank() || apiKey.isBlank()) {
throw new IllegalArgumentException("username and apiKey required");
} Try / catch
try {
Long userId = db.getUserId(username, apiKey);
} catch (IllegalArgumentException e) {
if (e.getMessage().contains("No user found")) {
// invalidate stored credentials and prompt re-authentication
}
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "User not found", "Invalid user", and "does not exist": what missing-user lookup errors mean across Rocket.Chat, LiteLLM, Phabricator, rustfs, and pnpm — this error's family across 10 libraries.
Related errors
- This server does not support username/password
- username must be set
- apiKey must be set
- This is the endpoint for the basic version of LanguageTool.
- WrongParameterNumberException
AI-assisted analysis of languagetool-org/languagetool@2e990059ce (2026-09-06).
Data as JSON: /api/errors/0aa3203d6a94fc1e.
Report an issue: GitHub.