SonarSource/sonarqube · error · IllegalArgumentException
Unexpected message type:
Error message
Unexpected message type:
What it means
The switch in verifyProjectKeyAndMessageType is exhaustive over known MessageType constants and ends with a default branch throwing 'Unexpected message type'. This is a defensive branch that triggers only if a new MessageType enum constant is added without updating this validation logic, or a null/unknown type reaches the method.
Source
Thrown at server/sonar-webserver-webapi/src/main/java/org/sonar/server/dismissmessage/ws/DismissMessageWsAction.java:50
return MessageType.valueOf(messageType);
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException("Invalid message type: " + messageType);
}
}
static void verifyProjectKeyAndMessageType(@Nullable String projectKey, MessageType type) {
switch (type) {
case GLOBAL_NCD_90, GLOBAL_NCD_PAGE_90, BITBUCKET_CLOUD_APP_DEPRECATION -> {
if (projectKey != null) {
throw new IllegalArgumentException("The 'projectKey' parameter is not expected for message type: " + type);
}
}
case PROJECT_NCD_90, PROJECT_NCD_PAGE_90, BRANCH_NCD_90, UNRESOLVED_FINDINGS_IN_AI_GENERATED_CODE -> {
if(projectKey == null) {
throw new IllegalArgumentException("The 'projectKey' parameter is missing for message type: " + type);
}
}
default -> throw new IllegalArgumentException("Unexpected message type: " + type);
}
}
}
View on GitHub (pinned to 184c821202)
Solutions
- Upgrade to a SonarQube version where the validation covers all MessageType constants (or report the mismatch as a bug).
- Never pass null or undefined message types; validate before calling.
- If maintaining a fork, add the new enum constant to the switch statement in verifyProjectKeyAndMessageType.
Example fix
// before
switch (type) {
case GLOBAL_NCD_90, ... -> ...
default -> throw new IllegalArgumentException("Unexpected message type: " + type);
}
// after
// add the missing constant to the switch:
case NEW_MESSAGE_TYPE -> { /* handle its projectKey rules */ } Defensive patterns
Strategy: try-catch
Validate before calling
if (messageType == null) {
throw new IllegalArgumentException("messageType is required");
} Try / catch
try {
ws.dismiss(messageType, projectKey);
} catch (IllegalArgumentException e) {
if (e.getMessage().startsWith("Unexpected message type:")) {
log.error("Server does not recognize message type {} — upgrade SonarQube or use a supported type", messageType);
} else throw e;
} Prevention
- Keep client and server SonarQube versions aligned.
- After upgrades, re-check that all message types in use are still supported.
- Never pass null message types into validation paths.
When it happens
Trigger: A SonarQube version adds a new MessageType constant but this action's validation was not updated; passing null as the type to verifyProjectKeyAndMessageType; reflection/manual enum value injection.
Common situations: Version upgrade with plugin/extension code calling this API; custom forks adding enum constants; NPE-style null propagation into the switch.
Understand the failure class
Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.
Related errors
- Invalid message type:
- Message '%s' cannot be dismissed.
- Unsupported WorkersPauseStatus: ${status}
- ${e.getMessage()}
- Cannot parse '%s' : %s
AI-assisted analysis of SonarSource/sonarqube@184c821202 (2026-09-09).
Data as JSON: /api/errors/80f51a596766acbd.
Report an issue: GitHub.