SonarSource/sonarqube · error · IllegalArgumentException

Invalid message type:

Error message

Invalid message type: 

What it means

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.

Source

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

 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */
package org.sonar.server.dismissmessage.ws;

import javax.annotation.Nullable;
import org.sonar.db.dismissmessage.MessageType;
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)

Solutions

  1. Pass the exact uppercase enum constant name (e.g. messageType=GLOBAL_NCD_90).
  2. Check the SonarQube version's MessageType enum for the valid constants, as names can change between versions.
  3. Trim whitespace and verify no lowercase/case-mismatch in the parameter.
  4. If the type was removed/renamed in a version upgrade, migrate to the new constant.

Example fix

// before
params.put("messageType", "global_ncd_90");
// after
params.put("messageType", "GLOBAL_NCD_90");
Defensive patterns

Strategy: validation

Validate before calling

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");
if (messageType == null || !VALID_TYPES.contains(messageType)) {
  throw new IllegalArgumentException("messageType must be an exact enum constant: " + VALID_TYPES);
}

Try / catch

try {
  ws.dismiss(messageType, projectKey);
} catch (IllegalArgumentException e) {
  if (e.getMessage().startsWith("Invalid message type:")) {
    log.error("Unknown messageType '{}'; check the enum for this SonarQube version", messageType);
  } else throw e;
}

Prevention

When it happens

Trigger: 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.

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

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


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