SonarSource/sonarqube · error · IllegalStateException
Ad-hoc rules export failed after processing %d rules success
Error message
Ad-hoc rules export failed after processing %d rules successfully
What it means
ExportAdHocRulesStep exports project-specific (ad-hoc) rules into the project dump via a streaming writer. Any exception thrown while iterating or converting rules is caught and rethrown as an IllegalStateException that reports how many rules were already successfully written. This lets operators know the dump is incomplete and how far the export got before failing.
Source
Thrown at server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectexport/rule/ExportAdHocRulesStep.java:72
@Override
public void execute(Context context) {
MutableLong count = MutableLong.valueOf(0L);
try (
StreamWriter<ProjectDump.AdHocRule> output = dumpWriter.newStreamWriter(DumpElement.AD_HOC_RULES);
DbSession dbSession = dbClient.openSession(false);
Cursor<RuleDto> ruleDtoCursor = dbClient.projectExportDao()
.scrollAdhocRulesForExport(dbSession, projectHolder.projectDto().getUuid())) {
ProjectDump.AdHocRule.Builder adHocRuleBuilder = ProjectDump.AdHocRule.newBuilder();
ruleDtoCursor
.forEach(ruleDto -> {
ProjectDump.AdHocRule rule = convertToAdHocRule(ruleDto, adHocRuleBuilder);
output.write(rule);
count.getAndInc();
});
LoggerFactory.getLogger(getClass()).debug("{} ad-hoc rules exported", count.value);
} catch (Exception e) {
throw new IllegalStateException(format("Ad-hoc rules export failed after processing %d rules successfully", count.value), e);
}
}
private static ProjectDump.AdHocRule convertToAdHocRule(RuleDto ruleDto, ProjectDump.AdHocRule.Builder builder) {
CleanCodeAttribute cleanCodeAttribute = ruleDto.getCleanCodeAttribute();
return builder
.clear()
.setRef(ruleDto.getUuid())
.setPluginKey(Optional.of(ruleDto).map(RuleDto::getPluginKey).orElse(""))
.setPluginRuleKey(ruleDto.getKey().rule())
.setPluginName(ruleDto.getRepositoryKey())
.setName(Optional.of(ruleDto).map(RuleDto::getName).orElse(""))
.setStatus(Optional.of(ruleDto).map(RuleDto::getStatus).map(Enum::name).orElse(""))
.setType(ruleDto.getType())
.setScope(ruleDto.getScope().name())
.setMetadata(buildMetadata(ruleDto))
.setCleanCodeAttribute(cleanCodeAttribute != null ? cleanCodeAttribute.name() : null)
.addAllImpacts(buildImpacts(ruleDto.getDefaultImpacts()))View on GitHub (pinned to 184c821202)
Solutions
- Check the cause chain (e.getCause()) to find the root failure — usually an IOException writing to the dump or a DB error
- Verify free disk space and write permissions on the CE working/export directory
- Inspect the ad-hoc rule rows for the project (RULES_ISSUES table) for corrupt or legacy data that fails conversion
- Re-run the export task after fixing the underlying cause; the dump is invalid and must be regenerated
Example fix
// before: streaming write can fail mid-loop
output.write(rule);
// after: ensure stream/dir is writable and handle per-rule conversion issues before export
if (!rootDir.canWrite()) { throw new IOException("dump dir not writable: " + rootDir); }
output.write(convertToAdHocRule(ruleDto, builder)); Defensive patterns
Strategy: try-catch
Validate before calling
if (!Files.isWritable(dumpRootDir)) { throw new IllegalStateException("Dump dir not writable"); } Try / catch
try { exportStep.execute(); } catch (IllegalStateException e) { logger.error("Ad-hoc rule export aborted: {}", e.getCause(), e); /* dump is invalid; do not publish */ } Prevention
- Monitor free disk space on the CE dump volume before large exports
- Validate ad-hoc rule data (clean code attributes) before running exports
- Keep DB connections healthy for long scrolling selects
When it happens
Trigger: Any exception (IOException from the output stream, protobuf serialization failure, DB error while scrolling rules, null cleanCodeAttribute conversion failure) thrown inside the rule iteration lambda of execute() after some rules have already been written.
Common situations: Disk full or dump directory not writable mid-export; protobuf write failure for a rule with unexpected/legacy data; database connectivity loss during the scrolling select of RULES_ISSUES ad-hoc rules.
Understand the failure class
Background: "failed to write file", "Could not save figure", "Error saving remote file" — file write failed: causes and fixes across languages and libraries — this error's family across 38 libraries.
Related errors
- Rule Export failed after processing %d rules successfully
- Can not write to file
- Fail to write into file:
- Fail to traverse file:
- Fail to open file
AI-assisted analysis of SonarSource/sonarqube@184c821202 (2026-09-09).
Data as JSON: /api/errors/31b3ecff15f561f3.
Report an issue: GitHub.