{"record":{"id":"f3e8fc47d08adfc2","repo":"SonarSource/sonarqube","slug":"an-s-event-with-the-same-name-already-exists-on","errorCode":null,"errorMessage":"An '%s' event with the same name already exists on analysis '%s'","messagePattern":"An '(.+?)' event with the same name already exists on analysis '(.+?)'","errorType":"http","errorClass":"IllegalArgumentException","httpStatus":400,"severity":"error","filePath":"server/sonar-webserver-webapi/src/main/java/org/sonar/server/projectanalysis/ws/CreateEventAction.java","lineNumber":206,"sourceCode":"    switch (request.getCategory()) {\n      case VERSION:\n        return dbEvent -> VERSION.getLabel().equals(dbEvent.getCategory());\n      case OTHER:\n        return dbEvent -> OTHER.getLabel().equals(dbEvent.getCategory()) && request.getName().equals(dbEvent.getName());\n      default:\n        throw new IllegalStateException(\"Event category not handled: \" + request.getCategory());\n    }\n  }\n\n  private static Consumer<EventDto> throwException(CreateEventRequest request) {\n    switch (request.getCategory()) {\n      case VERSION:\n        return dbEvent -> {\n          throw new IllegalArgumentException(format(\"A version event already exists on analysis '%s'\", request.getAnalysis()));\n        };\n      case OTHER:\n        return dbEvent -> {\n          throw new IllegalArgumentException(format(\"An '%s' event with the same name already exists on analysis '%s'\", OTHER.getLabel(), request.getAnalysis()));\n        };\n      default:\n        throw new IllegalStateException(\"Event category not handled: \" + request.getCategory());\n    }\n  }\n\n  private static class CreateEventRequest {\n    private final String analysis;\n    private final EventCategory category;\n    private final String name;\n\n    private CreateEventRequest(Builder builder) {\n      analysis = builder.analysis;\n      category = builder.category;\n      name = builder.name;\n    }\n\n    public String getAnalysis() {","sourceCodeStart":188,"sourceCodeEnd":224,"githubUrl":"https://github.com/SonarSource/sonarqube/blob/184c821202192afc1c599fc912d0889b69fffa53/server/sonar-webserver-webapi/src/main/java/org/sonar/server/projectanalysis/ws/CreateEventAction.java#L188-L224","documentation":"Thrown from CreateEventAction.throwException when creating an event of category OTHER (e.g. 'Quality Gate' status change) on an analysis that already has an event of that category with the exact same name. SonarQube forbids two same-named OTHER events on one analysis. The '%s' placeholder is filled with the category label.","triggerScenarios":"POST api/projects/create_event with category=OTHER (or QUALITY_GATE) and a name identical to an existing event on the same analysis uuid. Retrying a failed event-creation call. Automated importers writing alert/status events repeatedly.","commonSituations":"Scripts re-importing history that re-create events like 'Quality gate changed'; retry logic that replays a create_event request after a timeout although the first request succeeded.","solutions":["List existing events on the analysis and skip creation when an event with the same name/category already exists.","Delete the existing event (POST api/projects/delete_event) if the new event should replace it.","Rename the new event so it is unique on that analysis.","Make retries idempotent by correlating client-generated event names."],"exampleFix":"// before\ncreateEvent(analysisUuid, \"OTHER\", \"Quality gate changed\"); // 400 if duplicate\n// after\nboolean exists = getEvents(analysisUuid).stream()\n  .anyMatch(e -> \"OTHER\".equals(e.getCategory()) && \"Quality gate changed\".equals(e.getName()));\nif (!exists) {\n  createEvent(analysisUuid, \"OTHER\", \"Quality gate changed\");\n}","handlingStrategy":"validation","validationCode":"boolean dup = getEvents(analysisUuid).stream()\n  .anyMatch(e -> name.equals(e.getName()) && !\"VERSION\".equals(e.getCategory()));\nif (dup) { /* skip, rename, or delete existing */ }","typeGuard":null,"tryCatchPattern":"try {\n  createEvent(analysisUuid, \"OTHER\", name);\n} catch (SonarQubeClientException e) {\n  if (e.getMessage() != null && e.getMessage().contains(\"event with the same name already exists\")) {\n    LOG.info(\"duplicate OTHER event ignored\");\n  } else throw e;\n}","preventionTips":["Generate unique event names (include timestamp) in automation","Do not blind-retry create_event calls after timeouts without dedup checks","Fetch existing events before bulk imports"],"tags":["sonarqube","webapi","duplicate-resource","events"],"backgroundTag":"file-already-exists","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"}