{"record":{"id":"80f51a596766acbd","repo":"SonarSource/sonarqube","slug":"unexpected-message-type","errorCode":null,"errorMessage":"Unexpected message type: ","messagePattern":"Unexpected message type: ","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":400,"severity":"error","filePath":"server/sonar-webserver-webapi/src/main/java/org/sonar/server/dismissmessage/ws/DismissMessageWsAction.java","lineNumber":50,"sourceCode":"      return MessageType.valueOf(messageType);\n    } catch (IllegalArgumentException e) {\n      throw new IllegalArgumentException(\"Invalid message type: \" + messageType);\n    }\n  }\n\n  static void verifyProjectKeyAndMessageType(@Nullable String projectKey, MessageType type) {\n    switch (type) {\n      case GLOBAL_NCD_90, GLOBAL_NCD_PAGE_90, BITBUCKET_CLOUD_APP_DEPRECATION -> {\n        if (projectKey != null) {\n          throw new IllegalArgumentException(\"The 'projectKey' parameter is not expected for message type: \" + type);\n        }\n      }\n      case PROJECT_NCD_90, PROJECT_NCD_PAGE_90, BRANCH_NCD_90, UNRESOLVED_FINDINGS_IN_AI_GENERATED_CODE -> {\n        if(projectKey == null) {\n          throw new IllegalArgumentException(\"The 'projectKey' parameter is missing for message type: \" + type);\n        }\n      }\n      default -> throw new IllegalArgumentException(\"Unexpected message type: \" + type);\n    }\n  }\n}\n","sourceCodeStart":32,"sourceCodeEnd":54,"githubUrl":"https://github.com/SonarSource/sonarqube/blob/184c821202192afc1c599fc912d0889b69fffa53/server/sonar-webserver-webapi/src/main/java/org/sonar/server/dismissmessage/ws/DismissMessageWsAction.java#L32-L54","documentation":"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.","triggerScenarios":"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.","commonSituations":"Version upgrade with plugin/extension code calling this API; custom forks adding enum constants; NPE-style null propagation into the switch.","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."],"exampleFix":"// before\nswitch (type) {\n  case GLOBAL_NCD_90, ... -> ...\n  default -> throw new IllegalArgumentException(\"Unexpected message type: \" + type);\n}\n// after\n// add the missing constant to the switch:\n  case NEW_MESSAGE_TYPE -> { /* handle its projectKey rules */ }","handlingStrategy":"try-catch","validationCode":"if (messageType == null) {\n  throw new IllegalArgumentException(\"messageType is required\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  ws.dismiss(messageType, projectKey);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage().startsWith(\"Unexpected message type:\")) {\n    log.error(\"Server does not recognize message type {} — upgrade SonarQube or use a supported type\", messageType);\n  } else throw e;\n}","preventionTips":["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."],"tags":["java","sonarqube","web-api","enum"],"backgroundTag":"internal-invariant-violation","analyzedSha":"184c821202192afc1c599fc912d0889b69fffa53","analyzedAt":"2026-09-09T12:23:51.573Z","contentChangedAt":"2026-09-09T12:23:51.573Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}