SonarSource/sonarqube · error · IllegalArgumentException

Unknown event category label

Error message

Unknown event category label '%s'

What it means

EventCategory.fromLabel maps a human-readable category label (e.g. 'Version', 'Other') back to its enum constant; it throws IllegalArgumentException when no enum value carries that label. This guards callers from silently producing a null/unknown category.

Solutions

  1. Use the exact label constant from EventCategory (e.g. EventCategory.VERSION.getLabel()) instead of hardcoding strings.
  2. Normalize input case/trim before calling fromLabel.
  3. Prefer enum references over labels entirely; call fromLabel only for data you cannot control, wrapped in try-catch.
  4. For unknown labels from old data, fall back to EventCategory.OTHER or skip the record.

Example fix

// before
EventCategory category = EventCategory.fromLabel(userInput); // throws on typo
// after
EventCategory category;
try {
  category = EventCategory.fromLabel(userInput.trim());
} catch (IllegalArgumentException e) {
  category = EventCategory.OTHER;
}
Defensive patterns

Strategy: try-catch

Validate before calling

boolean known = Arrays.stream(EventCategory.values())
  .anyMatch(c -> c.getLabel().equals(label));

Type guard

static boolean isKnownCategoryLabel(String label) {
  return label != null && Arrays.stream(EventCategory.values())
    .anyMatch(c -> c.getLabel().equals(label));
}

Try / catch

try {
  category = EventCategory.fromLabel(label);
} catch (IllegalArgumentException e) {
  LOG.warn("unknown event category label: {}", label);
  category = EventCategory.OTHER;
}

Prevention

When it happens

Trigger: Calling EventCategory.fromLabel with a label string that does not exactly match any category label (case-sensitive, e.g. 'version' instead of 'Version'). Passing an old/renamed label from persisted data or an external payload.

Common situations: Plugins or custom integrations translating user input into categories; database rows written by older SonarQube versions whose labels changed; locale/case mismatches in labels.

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/9b9cbe49a17b104e. Report an issue: GitHub.

Appendix: source

Thrown at server/sonar-webserver-webapi/src/main/java/org/sonar/server/projectanalysis/ws/EventCategory.java:48

  private final String label;

  EventCategory(String label) {
    this.label = label;
  }

  public String getLabel() {
    return label;
  }

  public static EventCategory fromLabel(String label) {
    for (EventCategory category : values()) {
      if (category.getLabel().equals(label)) {
        return category;
      }
    }

    throw new IllegalArgumentException("Unknown event category label '" + label + "'");
  }
}

View on GitHub (pinned to 184c821202)