SonarSource/sonarqube · error · IllegalStateException
Measure Export failed after processing %d measures successfu
Error message
Measure Export failed after processing %d measures successfully
What it means
ExportMeasuresStep.execute() scrolls through all measures of a project and writes them to the export output, counting successes. If any exception occurs mid-export (DB read error, serialization failure, write failure), it wraps it in an IllegalStateException that reports how many measures were already exported successfully before the failure. It is thrown because a partial export cannot be resumed and the compute-engine task must fail loudly.
Source
Thrown at server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectexport/steps/ExportMeasuresStep.java:84
@Override
public void execute(Context context) {
long count = 0L;
try (
StreamWriter<ProjectDump.Measure> output = dumpWriter.newStreamWriter(DumpElement.MEASURES);
DbSession dbSession = dbClient.openSession(false);
PreparedStatement stmt = createSelectStatement(dbSession);
ResultSet rs = stmt.executeQuery()) {
ProjectDump.Measure.Builder measureBuilder = ProjectDump.Measure.newBuilder();
ProjectDump.DoubleValue.Builder doubleBuilder = ProjectDump.DoubleValue.newBuilder();
while (rs.next()) {
ProjectDump.Measure measure = convertToMeasure(rs, measureBuilder, doubleBuilder);
output.write(measure);
count++;
}
LoggerFactory.getLogger(getClass()).debug("{} measures exported", count);
} catch (Exception e) {
throw new IllegalStateException(format("Measure Export failed after processing %d measures successfully", count), e);
}
}
private PreparedStatement createSelectStatement(DbSession dbSession) throws SQLException {
PreparedStatement stmt = dbClient.getMyBatis().newScrollingSelectStatement(dbSession, QUERY);
try {
stmt.setString(1, projectHolder.projectDto().getUuid());
stmt.setBoolean(2, true);
stmt.setString(3, SnapshotDto.STATUS_PROCESSED);
stmt.setBoolean(4, true);
stmt.setBoolean(5, true);
return stmt;
} catch (Exception t) {
DatabaseUtils.closeQuietly(stmt);
throw t;
}
}
View on GitHub (pinned to 184c821202)
Solutions
- Inspect the wrapped cause exception (getCause()) to find the root failure and fix that issue
- Verify database connectivity and increase DB/socket timeouts for long-running export tasks
- Check free disk space on the CE worker where the project dump is written
- Re-run the export after remediation; the count tells how far it got, but the export restarts from zero
Example fix
// before
catch (Exception e) {
throw new IllegalStateException(format("Measure Export failed after processing %d measures successfully", count), e);
}
// after
// keep the IllegalStateException but log/inspect e.getCause():
catch (Exception e) {
LOGGER.error("Measure export failed at count {} due to {}", count, e.getCause(), e);
throw new IllegalStateException(format("Measure Export failed after processing %d measures successfully", count), e);
} Defensive patterns
Strategy: try-catch
Validate before calling
// pre-flight before export
try (DbSession db = dbClient.openSession(false)) {
long cnt = dbClient.getMeasureDao().countByComponentUuid(db, componentUuid);
if (cnt < 0) throw new IllegalStateException("DB unavailable for export");
} Try / catch
try {
exportMeasuresStep.execute(context);
} catch (IllegalStateException e) {
LOGGER.error("Measure export failed after N measures; cause: {}", e.getCause(), e);
// treat as task failure; do not retry blindly without fixing the cause
} Prevention
- Ensure stable DB connectivity and generous timeouts for long exports
- Monitor CE worker disk space before scheduling large exports
- Test exports against copies of large projects to catch row-level conversion issues
When it happens
Trigger: Any exception thrown while iterating the streaming measure ResultSet or calling output.write(measure) inside execute() — e.g. SQLException from createSelectStatement/scrolling cursor, protobuf conversion failure, or I/O error writing to the dump output.
Common situations: Database connection drops or times out during a long scrolling select on a large project; disk full on the CE worker while writing the dump; a corrupted or incompatible measure row that fails protobuf conversion during export.
Understand the failure class
Background: Database query failed: Internal Server Error 500s wrapping SQL, Prisma, and connection failures — what to check first — this error's family across 16 libraries.
Related errors
- Metric Export failed after processing %d metrics successfull
- New Code Periods Export failed after processing %d new code
- Settings Export failed after processing %d settings successf
- Analysis report %s part %s is missing in database
- Analysis Export failed after processing %d analyses successf
AI-assisted analysis of SonarSource/sonarqube@184c821202 (2026-09-09).
Data as JSON: /api/errors/5a1b82ae6fc79df7.
Report an issue: GitHub.