{"record":{"id":"36c3848d1b50d464","repo":"SonarSource/sonarqube","slug":"a-version-event-already-exists-on-analysis-s","errorCode":null,"errorMessage":"A version event already exists on analysis '%s'","messagePattern":"A version event 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":202,"sourceCode":"      .ifPresent(throwException(request));\n  }\n\n  private static Predicate<EventDto> filterSimilarEvents(CreateEventRequest request) {\n    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;","sourceCodeStart":184,"sourceCodeEnd":220,"githubUrl":"https://github.com/SonarSource/sonarqube/blob/184c821202192afc1c599fc912d0889b69fffa53/server/sonar-webserver-webapi/src/main/java/org/sonar/server/projectanalysis/ws/CreateEventAction.java#L184-L220","documentation":"SonarQube throws this IllegalArgumentException from CreateEventAction.throwException when a client attempts to create a VERSION event on an analysis that already has one. An analysis can hold at most one version event, so the server rejects duplicates with a 400 response. The check runs against existing DB events for the target analysis before insert.","triggerScenarios":"POST api/projects/create_event with category=VERSION on an analysis uuid that already has a version event. Calling the API twice for the same analysis (double-click/retry of a non-idempotent call). Automation that publishes a version per build without checking for an existing one.","commonSituations":"CI pipelines re-running a publish step after a partial failure; scripts using the same analysis uuid; users manually creating a second 'Version' event in the UI for an analysis that already has one.","solutions":["Check existing events first (GET api/events?analysis=<uuid>) and skip creation or delete the old version event (POST api/projects/delete_event) before creating a new one.","Make the pipeline step idempotent: catch the 400 and treat 'version already exists' as success.","Ensure each build creates a NEW analysis (e.g. correct CE report) rather than reusing an analysis uuid."],"exampleFix":"// before\ncallCreateEvent(analysisUuid, \"VERSION\", \"1.2.3\"); // fails on retry\n// after\nList<Event> events = getEvents(analysisUuid);\nEvent existing = events.stream().filter(e -> \"VERSION\".equals(e.getCategory())).findFirst().orElse(null);\nif (existing != null) {\n  deleteEvent(existing.getUuid());\n}\ncallCreateEvent(analysisUuid, \"VERSION\", \"1.2.3\");","handlingStrategy":"validation","validationCode":"List<Event> events = getEvents(analysisUuid); // GET api/events?analysis=<uuid>\nboolean hasVersion = events.stream().anyMatch(e -> \"VERSION\".equals(e.getCategory()));\nif (hasVersion) { /* skip create or delete existing first */ }","typeGuard":null,"tryCatchPattern":"try {\n  createEvent(analysisUuid, \"VERSION\", version);\n} catch (FeignException | SonarQubeClientException e) {\n  if (String.valueOf(e.getMessage()).contains(\"version event already exists\")) {\n    LOG.info(\"version event already present; treating as success\");\n  } else throw e;\n}","preventionTips":["Check existing events for the analysis before creating any event","Make CI publish steps idempotent and safe to retry","Never reuse analysis uuids across builds"],"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"}