{"record":{"id":"87d7691e0add495f","repo":"SonarSource/sonarqube","slug":"rule-export-failed-after-processing-d-rules-succe","errorCode":null,"errorMessage":"Rule Export failed after processing %d rules successfully","messagePattern":"Rule Export failed after processing (.+?) rules successfully","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectexport/rule/ExportRuleStep.java","lineNumber":57,"sourceCode":"\n  @Override\n  public String getDescription() {\n    return \"Export rules\";\n  }\n\n  @Override\n  public void execute(Context context) {\n    long count = 0;\n    try (StreamWriter<ProjectDump.Rule> writer = dumpWriter.newStreamWriter(DumpElement.RULES)) {\n      ProjectDump.Rule.Builder ruleBuilder = ProjectDump.Rule.newBuilder();\n      for (Rule rule : ruleRepository.getAll()) {\n        ProjectDump.Rule ruleMessage = toRuleMessage(ruleBuilder, rule);\n        writer.write(ruleMessage);\n        count++;\n      }\n      LoggerFactory.getLogger(getClass()).debug(\"{} rules exported\", count);\n    } catch (Exception e) {\n      throw new IllegalStateException(format(\"Rule Export failed after processing %d rules successfully\", count), e);\n    }\n  }\n\n  private static ProjectDump.Rule toRuleMessage(ProjectDump.Rule.Builder ruleBuilder, Rule rule) {\n    ruleBuilder.clear();\n    return ruleBuilder\n      .setRef(rule.ref())\n      .setKey(rule.key())\n      .setRepository(rule.repository())\n      .build();\n  }\n}\n","sourceCodeStart":39,"sourceCodeEnd":70,"githubUrl":"https://github.com/SonarSource/sonarqube/blob/184c821202192afc1c599fc912d0889b69fffa53/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectexport/rule/ExportRuleStep.java#L39-L70","documentation":"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.","triggerScenarios":"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.","commonSituations":"Corrupt rule data in the RULES table after an upgrade/plugin removal; protobuf writer IO failure; DB scroll failure during rule enumeration.","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"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"long corrupt = rules.stream().filter(r -> r.getRepositoryKey() == null || r.getRuleKey() == null).count();\nif (corrupt > 0) { throw new IllegalStateException(corrupt + \" rules with null keys\"); }","typeGuard":null,"tryCatchPattern":"try { exportRuleStep.execute(); } catch (IllegalStateException e) { logger.error(\"Rule export failed at rule #{}: {}\", extractCount(e), e.getCause(), e); }","preventionTips":["Verify rule plugin versions match between environments before export","Clean up orphaned rules left by removed plugins","Ensure disk capacity before export"],"tags":["sonarqube","project-export","rules","dump-export"],"backgroundTag":"internal-invariant-violation","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"}