SonarSource/sonarqube · error · IllegalStateException
Rule Export failed after processing %d rules successfully
Error message
Rule Export failed after processing %d rules successfully
What it means
ExportRuleStep serializes all standard rules into ProjectDump.Rule protobuf messages and writes them to the dump. Any exception during iteration/conversion is wrapped in an IllegalStateException reporting the number of rules successfully processed. The count tells you the export died partway through, so the dump is incomplete.
Source
Thrown at server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectexport/rule/ExportRuleStep.java:57
@Override
public String getDescription() {
return "Export rules";
}
@Override
public void execute(Context context) {
long count = 0;
try (StreamWriter<ProjectDump.Rule> writer = dumpWriter.newStreamWriter(DumpElement.RULES)) {
ProjectDump.Rule.Builder ruleBuilder = ProjectDump.Rule.newBuilder();
for (Rule rule : ruleRepository.getAll()) {
ProjectDump.Rule ruleMessage = toRuleMessage(ruleBuilder, rule);
writer.write(ruleMessage);
count++;
}
LoggerFactory.getLogger(getClass()).debug("{} rules exported", count);
} catch (Exception e) {
throw new IllegalStateException(format("Rule Export failed after processing %d rules successfully", count), e);
}
}
private static ProjectDump.Rule toRuleMessage(ProjectDump.Rule.Builder ruleBuilder, Rule rule) {
ruleBuilder.clear();
return ruleBuilder
.setRef(rule.ref())
.setKey(rule.key())
.setRepository(rule.repository())
.build();
}
}
View on GitHub (pinned to 184c821202)
Solutions
- Read the wrapped cause to identify whether it is IO (disk/stream) or data (conversion) related
- Check RULES table rows for rules with null/invalid fields, especially around plugin upgrades or removed plugins
- Verify disk space and permissions for the export directory
- Fix the offending rule data or restore the plugin, then rerun the export
Defensive patterns
Strategy: try-catch
Validate before calling
long corrupt = rules.stream().filter(r -> r.getRepositoryKey() == null || r.getRuleKey() == null).count();
if (corrupt > 0) { throw new IllegalStateException(corrupt + " rules with null keys"); } Try / catch
try { exportRuleStep.execute(); } catch (IllegalStateException e) { logger.error("Rule export failed at rule #{}: {}", extractCount(e), e.getCause(), e); } Prevention
- Verify rule plugin versions match between environments before export
- Clean up orphaned rules left by removed plugins
- Ensure disk capacity before export
When it happens
Trigger: Exception thrown in toRuleMessage() (e.g. malformed RuleDto fields such as null template/security classifications) or a write failure on the StreamWriter during the rules loop after `count` rules were written.
Common situations: Corrupt rule data in the RULES table after an upgrade/plugin removal; protobuf writer IO failure; DB scroll failure during rule enumeration.
Understand the failure class
Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.
Related errors
- Ad-hoc rules export failed after processing %d rules success
- Specified RuleKey '%s' is not equal to the one already regis
- Metadata has already been written
- Can not write to file
- Metadata is missing
AI-assisted analysis of SonarSource/sonarqube@184c821202 (2026-09-09).
Data as JSON: /api/errors/87d7691e0add495f.
Report an issue: GitHub.