SonarSource/sonarqube · error · IllegalArgumentException

The 'projectKey' parameter is not expected for message…

Error message

The 'projectKey' parameter is not expected for message type: 

What it means

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.

Solutions

  1. Omit projectKey when dismissing global message types (GLOBAL_NCD_90, GLOBAL_NCD_PAGE_90, BITBUCKET_CLOUD_APP_DEPRECATION).
  2. Use a project-scoped type (e.g. PROJECT_NCD_90) if you actually intend to dismiss the message for a specific project.
  3. Remove the projectKey parameter from shared request-building code when the type is global.

Example fix

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

Strategy: validation

Validate before calling

Set<String> GLOBAL_TYPES = Set.of("GLOBAL_NCD_90","GLOBAL_NCD_PAGE_90","BITBUCKET_CLOUD_APP_DEPRECATION");
if (GLOBAL_TYPES.contains(messageType) && projectKey != null) {
  throw new IllegalArgumentException("projectKey must be omitted for global message type " + messageType);
}

Try / catch

try {
  ws.dismiss(messageType, projectKey);
} catch (IllegalArgumentException e) {
  if (e.getMessage().startsWith("The 'projectKey' parameter is not expected")) {
    ws.dismiss(messageType, null); // retry without projectKey
  } else throw e;
}

Prevention

When it happens

Trigger: Calling the dismiss-message WS with e.g. messageType=GLOBAL_NCD_90 together with a projectKey parameter.

Common situations: Client code that always attaches projectKey; reusing a request builder for both project-scoped and global dismissals without clearing parameters.

Understand the failure class

Background: "Invalid query parameter" / "Failed to parse value of ...": fixing bad query string parameters across APIs — this error's family across 36 libraries.

Related errors


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

Appendix: source

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

import org.sonar.server.ws.WsAction;

public interface DismissMessageWsAction extends WsAction {
  String PARAM_PROJECT_KEY = "projectKey";
  String PARAM_MESSAGE_TYPE = "messageType";

  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)