SonarSource/sonarqube · error · IllegalArgumentException

The 'projectKey' parameter is missing for message type:

Error message

The 'projectKey' parameter is missing for message type: 

What it means

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.

Solutions

  1. Add the projectKey parameter matching the project the message belongs to.
  2. Verify the project key is non-empty and correctly passed by the calling script/UI.
  3. Use a global message type only if the dismissal is not project-specific.

Example fix

// before
POST /api/messages/dismiss?messageType=PROJECT_NCD_90
// after
POST /api/messages/dismiss?messageType=PROJECT_NCD_90&projectKey=my_project
Defensive patterns

Strategy: validation

Validate before calling

Set<String> PROJECT_TYPES = Set.of("PROJECT_NCD_90","PROJECT_NCD_PAGE_90","BRANCH_NCD_90","UNRESOLVED_FINDINGS_IN_AI_GENERATED_CODE");
if (PROJECT_TYPES.contains(messageType) && (projectKey == null || projectKey.isBlank())) {
  throw new IllegalArgumentException("projectKey is required for message type " + messageType);
}

Try / catch

try {
  ws.dismiss(messageType, projectKey);
} catch (IllegalArgumentException e) {
  if (e.getMessage().startsWith("The 'projectKey' parameter is missing")) {
    log.error("Cannot dismiss {}: project context missing", messageType);
  } else throw e;
}

Prevention

When it happens

Trigger: Calling the dismiss-message WS with e.g. messageType=PROJECT_NCD_90 but no projectKey parameter.

Common situations: 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.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of SonarSource/sonarqube@184c821202 (2026-09-09). Data as JSON: /api/errors/a9919c429e16bb50. Report an issue: GitHub.

Appendix: source

Thrown at server/sonar-webserver-webapi/src/main/java/org/sonar/server/dismissmessage/ws/DismissMessageWsAction.java:47

  static MessageType parseMessageType(String messageType) throws IllegalArgumentException {
    try {
      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)