{"record":{"id":"9b9cbe49a17b104e","repo":"SonarSource/sonarqube","slug":"unknown-event-category-label-s","errorCode":null,"errorMessage":"Unknown event category label '%s'","messagePattern":"Unknown event category label '(.+?)'","errorType":"http","errorClass":"IllegalArgumentException","httpStatus":400,"severity":"error","filePath":"server/sonar-webserver-webapi/src/main/java/org/sonar/server/projectanalysis/ws/EventCategory.java","lineNumber":48,"sourceCode":"\n  private final String label;\n\n  EventCategory(String label) {\n    this.label = label;\n  }\n\n  public String getLabel() {\n    return label;\n  }\n\n  public static EventCategory fromLabel(String label) {\n    for (EventCategory category : values()) {\n      if (category.getLabel().equals(label)) {\n        return category;\n      }\n    }\n\n    throw new IllegalArgumentException(\"Unknown event category label '\" + label + \"'\");\n  }\n}\n","sourceCodeStart":30,"sourceCodeEnd":51,"githubUrl":"https://github.com/SonarSource/sonarqube/blob/184c821202192afc1c599fc912d0889b69fffa53/server/sonar-webserver-webapi/src/main/java/org/sonar/server/projectanalysis/ws/EventCategory.java#L30-L51","documentation":"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.","triggerScenarios":"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.","commonSituations":"Plugins or custom integrations translating user input into categories; database rows written by older SonarQube versions whose labels changed; locale/case mismatches in labels.","solutions":["Use the exact label constant from EventCategory (e.g. EventCategory.VERSION.getLabel()) instead of hardcoding strings.","Normalize input case/trim before calling fromLabel.","Prefer enum references over labels entirely; call fromLabel only for data you cannot control, wrapped in try-catch.","For unknown labels from old data, fall back to EventCategory.OTHER or skip the record."],"exampleFix":"// before\nEventCategory category = EventCategory.fromLabel(userInput); // throws on typo\n// after\nEventCategory category;\ntry {\n  category = EventCategory.fromLabel(userInput.trim());\n} catch (IllegalArgumentException e) {\n  category = EventCategory.OTHER;\n}","handlingStrategy":"try-catch","validationCode":"boolean known = Arrays.stream(EventCategory.values())\n  .anyMatch(c -> c.getLabel().equals(label));","typeGuard":"static boolean isKnownCategoryLabel(String label) {\n  return label != null && Arrays.stream(EventCategory.values())\n    .anyMatch(c -> c.getLabel().equals(label));\n}","tryCatchPattern":"try {\n  category = EventCategory.fromLabel(label);\n} catch (IllegalArgumentException e) {\n  LOG.warn(\"unknown event category label: {}\", label);\n  category = EventCategory.OTHER;\n}","preventionTips":["Reference enum constants/labels instead of hardcoding label strings","Trim and case-normalize external label input","Verify labels against the current SonarQube version when migrating data"],"tags":["sonarqube","webapi","enum-mapping","invalid-input"],"backgroundTag":"invalid-enum-value","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"}