{"record":{"id":"f3f43db10d2ff215","repo":"SonarSource/sonarqube","slug":"the-projectkey-parameter-is-not-expected-for-mes","errorCode":null,"errorMessage":"The 'projectKey' parameter is not expected for message type: ","messagePattern":"The 'projectKey' parameter is not expected for 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":42,"sourceCode":"import 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  }\n}\n","sourceCodeStart":24,"sourceCodeEnd":54,"githubUrl":"https://github.com/SonarSource/sonarqube/blob/184c821202192afc1c599fc912d0889b69fffa53/server/sonar-webserver-webapi/src/main/java/org/sonar/server/dismissmessage/ws/DismissMessageWsAction.java#L24-L54","documentation":"Some message types (GLOBAL_NCD_90, GLOBAL_NCD_PAGE_90, BITBUCKET_CLOUD_APP_DEPRECATION) are global and must NOT be scoped to a project. verifyProjectKeyAndMessageType throws this IllegalArgumentException when a projectKey parameter is supplied alongside one of these global types.","triggerScenarios":"Calling the dismiss-message WS with e.g. messageType=GLOBAL_NCD_90 together with a projectKey parameter.","commonSituations":"Client code that always attaches projectKey; reusing a request builder for both project-scoped and global dismissals without clearing parameters.","solutions":["Omit projectKey when dismissing global message types (GLOBAL_NCD_90, GLOBAL_NCD_PAGE_90, BITBUCKET_CLOUD_APP_DEPRECATION).","Use a project-scoped type (e.g. PROJECT_NCD_90) if you actually intend to dismiss the message for a specific project.","Remove the projectKey parameter from shared request-building code when the type is global."],"exampleFix":"// before\nPOST /api/messages/dismiss?messageType=GLOBAL_NCD_90&projectKey=my_project\n// after\nPOST /api/messages/dismiss?messageType=GLOBAL_NCD_90","handlingStrategy":"validation","validationCode":"Set<String> GLOBAL_TYPES = Set.of(\"GLOBAL_NCD_90\",\"GLOBAL_NCD_PAGE_90\",\"BITBUCKET_CLOUD_APP_DEPRECATION\");\nif (GLOBAL_TYPES.contains(messageType) && projectKey != null) {\n  throw new IllegalArgumentException(\"projectKey must be omitted for global message type \" + messageType);\n}","typeGuard":null,"tryCatchPattern":"try {\n  ws.dismiss(messageType, projectKey);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage().startsWith(\"The 'projectKey' parameter is not expected\")) {\n    ws.dismiss(messageType, null); // retry without projectKey\n  } else throw e;\n}","preventionTips":["Keep a single request builder that conditionally includes projectKey based on the type.","Remember: global types forbid projectKey, project types require it.","Document which message types are global in client code."],"tags":["java","sonarqube","web-api","parameter-validation"],"backgroundTag":"invalid-query-parameter","analyzedSha":"184c821202192afc1c599fc912d0889b69fffa53","analyzedAt":"2026-09-09T12:23:51.573Z","contentChangedAt":"2026-09-09T12:23:51.573Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}