{"record":{"id":"a9919c429e16bb50","repo":"SonarSource/sonarqube","slug":"the-projectkey-parameter-is-missing-for-message","errorCode":null,"errorMessage":"The 'projectKey' parameter is missing for message type: ","messagePattern":"The 'projectKey' parameter is missing 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":47,"sourceCode":"\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":29,"sourceCodeEnd":54,"githubUrl":"https://github.com/SonarSource/sonarqube/blob/184c821202192afc1c599fc912d0889b69fffa53/server/sonar-webserver-webapi/src/main/java/org/sonar/server/dismissmessage/ws/DismissMessageWsAction.java#L29-L54","documentation":"Project-scoped message types (PROJECT_NCD_90, PROJECT_NCD_PAGE_90, BRANCH_NCD_90, UNRESOLVED_FINDINGS_IN_AI_GENERATED_CODE) require a projectKey to identify which project the dismissal applies to. verifyProjectKeyAndMessageType throws this IllegalArgumentException when projectKey is null/absent for these types.","triggerScenarios":"Calling the dismiss-message WS with e.g. messageType=PROJECT_NCD_90 but no projectKey parameter.","commonSituations":"Copying a global-dismissal request (which forbids projectKey) and only changing the message type; UI/CLI flows losing the project context; scripts parameterized with an empty project key that serializes as absent.","solutions":["Add the projectKey parameter matching the project the message belongs to.","Verify the project key is non-empty and correctly passed by the calling script/UI.","Use a global message type only if the dismissal is not project-specific."],"exampleFix":"// before\nPOST /api/messages/dismiss?messageType=PROJECT_NCD_90\n// after\nPOST /api/messages/dismiss?messageType=PROJECT_NCD_90&projectKey=my_project","handlingStrategy":"validation","validationCode":"Set<String> PROJECT_TYPES = Set.of(\"PROJECT_NCD_90\",\"PROJECT_NCD_PAGE_90\",\"BRANCH_NCD_90\",\"UNRESOLVED_FINDINGS_IN_AI_GENERATED_CODE\");\nif (PROJECT_TYPES.contains(messageType) && (projectKey == null || projectKey.isBlank())) {\n  throw new IllegalArgumentException(\"projectKey is required for 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 missing\")) {\n    log.error(\"Cannot dismiss {}: project context missing\", messageType);\n  } else throw e;\n}","preventionTips":["Resolve and pass the project key before dismissing project-scoped messages.","Treat empty-string project keys as missing.","Only use global types when the dismissal is not tied to a project."],"tags":["java","sonarqube","web-api","parameter-validation"],"backgroundTag":"missing-required-argument","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"}