{"record":{"id":"bf9d535704de284b","repo":"SonarSource/sonarqube","slug":"invalid-message-type","errorCode":null,"errorMessage":"Invalid message type: ","messagePattern":"Invalid 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":34,"sourceCode":" * You should have received a copy of the GNU Lesser General Public License\n * along with this program; if not, write to the Free Software Foundation,\n * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.\n */\npackage org.sonar.server.dismissmessage.ws;\n\nimport javax.annotation.Nullable;\nimport org.sonar.db.dismissmessage.MessageType;\nimport org.sonar.server.ws.WsAction;\n\npublic interface DismissMessageWsAction extends WsAction {\n  String PARAM_PROJECT_KEY = \"projectKey\";\n  String PARAM_MESSAGE_TYPE = \"messageType\";\n\n  static MessageType parseMessageType(String messageType) throws IllegalArgumentException {\n    try {\n      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  }","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/SonarSource/sonarqube/blob/184c821202192afc1c599fc912d0889b69fffa53/server/sonar-webserver-webapi/src/main/java/org/sonar/server/dismissmessage/ws/DismissMessageWsAction.java#L16-L52","documentation":"The dismiss-message WS ('api/messages/dismiss' family) requires the messageType parameter to be one of the enum MessageType values (e.g. GLOBAL_NCD_90, PROJECT_NCD_90). parseMessageType converts any unknown value's IllegalArgumentException from MessageType.valueOf into this clearer error.","triggerScenarios":"Calling the dismiss-message WS with messageType that is not an exact enum constant name: lowercase ('global_ncd_90'), old/renamed type names, typos, or empty values.","commonSituations":"Hardcoded message types from an older SonarQube version whose enum constants changed; documentation examples typed with wrong casing; scripts sending human-readable labels instead of enum constants.","solutions":["Pass the exact uppercase enum constant name (e.g. messageType=GLOBAL_NCD_90).","Check the SonarQube version's MessageType enum for the valid constants, as names can change between versions.","Trim whitespace and verify no lowercase/case-mismatch in the parameter.","If the type was removed/renamed in a version upgrade, migrate to the new constant."],"exampleFix":"// before\nparams.put(\"messageType\", \"global_ncd_90\");\n// after\nparams.put(\"messageType\", \"GLOBAL_NCD_90\");","handlingStrategy":"validation","validationCode":"Set<String> VALID_TYPES = Set.of(\"GLOBAL_NCD_90\",\"GLOBAL_NCD_PAGE_90\",\"BITBUCKET_CLOUD_APP_DEPRECATION\",\"PROJECT_NCD_90\",\"PROJECT_NCD_PAGE_90\",\"BRANCH_NCD_90\",\"UNRESOLVED_FINDINGS_IN_AI_GENERATED_CODE\");\nif (messageType == null || !VALID_TYPES.contains(messageType)) {\n  throw new IllegalArgumentException(\"messageType must be an exact enum constant: \" + VALID_TYPES);\n}","typeGuard":null,"tryCatchPattern":"try {\n  ws.dismiss(messageType, projectKey);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage().startsWith(\"Invalid message type:\")) {\n    log.error(\"Unknown messageType '{}'; check the enum for this SonarQube version\", messageType);\n  } else throw e;\n}","preventionTips":["Reference enum constant names from code/constants, never hand-typed strings.","Verify valid message types after each SonarQube upgrade.","Uppercase and trim the value before sending."],"tags":["java","sonarqube","web-api","enum"],"backgroundTag":"invalid-enum-value","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"}