{"record":{"id":"32c59b65758494b8","repo":"SonarSource/sonarqube","slug":"the-default-quality-gate-is-missing","errorCode":null,"errorMessage":"The default Quality gate is missing","messagePattern":"The default Quality gate is missing","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"critical","filePath":"server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/qualitygate/QualityGateServiceImpl.java","lineNumber":50,"sourceCode":"public class QualityGateServiceImpl implements QualityGateService {\n  private final DbClient dbClient;\n  private final MetricRepository metricRepository;\n\n  public QualityGateServiceImpl(DbClient dbClient, MetricRepository metricRepository) {\n    this.dbClient = dbClient;\n    this.metricRepository = metricRepository;\n  }\n\n  @Override\n  public QualityGate findEffectiveQualityGate(Project project) {\n    return findQualityGate(project).orElseGet(this::findDefaultQualityGate);\n  }\n\n  private QualityGate findDefaultQualityGate() {\n    try (DbSession dbSession = dbClient.openSession(false)) {\n      QualityGateDto qualityGateDto = dbClient.qualityGateDao().selectDefault(dbSession);\n      if (qualityGateDto == null) {\n        throw new IllegalStateException(\"The default Quality gate is missing\");\n      }\n      return toQualityGate(dbSession, qualityGateDto);\n    }\n  }\n\n  private Optional<QualityGate> findQualityGate(Project project) {\n    try (DbSession dbSession = dbClient.openSession(false)) {\n      return Optional.ofNullable(dbClient.qualityGateDao().selectByProjectUuid(dbSession, project.getUuid()))\n        .map(qg -> toQualityGate(dbSession, qg));\n    }\n  }\n\n  private QualityGate toQualityGate(DbSession dbSession, QualityGateDto qualityGateDto) {\n    Collection<QualityGateConditionDto> dtos = dbClient.gateConditionDao().selectForQualityGate(dbSession, qualityGateDto.getUuid());\n\n    Collection<Condition> conditions = dtos.stream()\n      .map(input -> metricRepository.getOptionalByUuid(input.getMetricUuid())\n        .map(metric -> new Condition(metric, input.getOperator(), input.getErrorThreshold()))","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/SonarSource/sonarqube/blob/184c821202192afc1c599fc912d0889b69fffa53/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/qualitygate/QualityGateServiceImpl.java#L32-L68","documentation":"QualityGateServiceImpl.findDefaultQualityGate() looks up the Quality Gate flagged as default (QUALITY_GATE default) in the database. If qualityGateDao().selectDefault() returns null — no gate is marked default — it throws IllegalStateException 'The default Quality gate is missing'. The Compute Engine relies on a default gate existing to evaluate projects without an explicit gate assignment.","triggerScenarios":"Computing a project analysis whose project is not bound to a specific Quality Gate, so the code falls back to the default gate, and no row in the quality_gates table has default=true — e.g. after a corrupted import, manual SQL deletion, or a migration failure.","commonSituations":"Restoring a database backup without the default gate, deleting the 'Sonar way' gate, bulk-gate management scripts that unset default, or broken upgrade paths between SonarQube versions.","solutions":["Open Administration > Quality Gates and ensure one gate (e.g. 'Sonar way') is set as the default — hover the gate and choose 'Set as default'","Recreate the default gate via API/web service if the UI lacks it: POST api/qualitygates/set_default with the gate id","Check the quality_gates table: SELECT id,name FROM quality_gates WHERE default_gate=true (or equivalent) and fix with an UPDATE if the default flag was lost"],"exampleFix":"// check and fix via web API\ncurl -u admin:token -X POST 'https://sonar.example.com/api/qualitygates/set_default?id=AYxSonarWayId'\n// SQL inspection\nSELECT id, name FROM quality_gates WHERE default_gate = true; -- must return 1 row","handlingStrategy":"try-catch","validationCode":"// verify a default gate exists before running analyses\ncurl -u admin:token 'https://sonar.example.com/api/qualitygates/list' | jq '.qualitygates[] | select(.isDefault == true)'\n// empty output -> no default gate; set one before launching CE tasks","typeGuard":null,"tryCatchPattern":"try {\n  QualityGate gate = qualityGateService.getDefaultQualityEngine();\n} catch (IllegalStateException e) {\n  if (e.getMessage().equals(\"The default Quality gate is missing\")) {\n    // recover: mark a gate as default via DB or web service, then retry\n    adminApi.setDefaultGate(\"Sonar way\");\n  } else throw e;\n}","preventionTips":["Never delete or tamper with the 'Sonar way' default Quality Gate","After DB restores or upgrade migrations, verify one quality_gates row has default=true","Use api/qualitygates/set_default rather than direct SQL to manage the default","Add a post-restore smoke check that the default gate resolves"],"tags":["quality-gate","database","missing-data"],"backgroundTag":"entity-not-found","analyzedSha":"184c821202192afc1c599fc912d0889b69fffa53","analyzedAt":"2026-09-09T12:23:51.573Z","contentChangedAt":"2026-09-09T12:23:51.573Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}