SonarSource/sonarqube · critical · IllegalStateException
The default Quality gate is missing
Error message
The default Quality gate is missing
What it means
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.
Source
Thrown at server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/qualitygate/QualityGateServiceImpl.java:50
public class QualityGateServiceImpl implements QualityGateService {
private final DbClient dbClient;
private final MetricRepository metricRepository;
public QualityGateServiceImpl(DbClient dbClient, MetricRepository metricRepository) {
this.dbClient = dbClient;
this.metricRepository = metricRepository;
}
@Override
public QualityGate findEffectiveQualityGate(Project project) {
return findQualityGate(project).orElseGet(this::findDefaultQualityGate);
}
private QualityGate findDefaultQualityGate() {
try (DbSession dbSession = dbClient.openSession(false)) {
QualityGateDto qualityGateDto = dbClient.qualityGateDao().selectDefault(dbSession);
if (qualityGateDto == null) {
throw new IllegalStateException("The default Quality gate is missing");
}
return toQualityGate(dbSession, qualityGateDto);
}
}
private Optional<QualityGate> findQualityGate(Project project) {
try (DbSession dbSession = dbClient.openSession(false)) {
return Optional.ofNullable(dbClient.qualityGateDao().selectByProjectUuid(dbSession, project.getUuid()))
.map(qg -> toQualityGate(dbSession, qg));
}
}
private QualityGate toQualityGate(DbSession dbSession, QualityGateDto qualityGateDto) {
Collection<QualityGateConditionDto> dtos = dbClient.gateConditionDao().selectForQualityGate(dbSession, qualityGateDto.getUuid());
Collection<Condition> conditions = dtos.stream()
.map(input -> metricRepository.getOptionalByUuid(input.getMetricUuid())
.map(metric -> new Condition(metric, input.getOperator(), input.getErrorThreshold()))View on GitHub (pinned to 184c821202)
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
Example fix
// check and fix via web API curl -u admin:token -X POST 'https://sonar.example.com/api/qualitygates/set_default?id=AYxSonarWayId' // SQL inspection SELECT id, name FROM quality_gates WHERE default_gate = true; -- must return 1 row
Defensive patterns
Strategy: try-catch
Validate before calling
// verify a default gate exists before running analyses curl -u admin:token 'https://sonar.example.com/api/qualitygates/list' | jq '.qualitygates[] | select(.isDefault == true)' // empty output -> no default gate; set one before launching CE tasks
Try / catch
try {
QualityGate gate = qualityGateService.getDefaultQualityEngine();
} catch (IllegalStateException e) {
if (e.getMessage().equals("The default Quality gate is missing")) {
// recover: mark a gate as default via DB or web service, then retry
adminApi.setDefaultGate("Sonar way");
} else throw e;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "Not found" and "does not exist" errors: why "Task not found", "No such folder", and "Can't find" fire when a lookup comes back empty — this error's family across 14 libraries.
Related errors
- Analysis report %s part %s is missing in database
- Quality Gate: Unable to parse value '%s' to compare against
- Unsupported value '%s' of Measure.Level can not be converted
- Unsupported value '%s' of Measure.Level can not be converted
- Analysis Export failed after processing %d analyses successf
AI-assisted analysis of SonarSource/sonarqube@184c821202 (2026-09-09).
Data as JSON: /api/errors/32c59b65758494b8.
Report an issue: GitHub.