{"record":{"id":"31b3ecff15f561f3","repo":"SonarSource/sonarqube","slug":"ad-hoc-rules-export-failed-after-processing-d-rul","errorCode":null,"errorMessage":"Ad-hoc rules export failed after processing %d rules successfully","messagePattern":"Ad-hoc rules 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/ExportAdHocRulesStep.java","lineNumber":72,"sourceCode":"  @Override\n  public void execute(Context context) {\n    MutableLong count = MutableLong.valueOf(0L);\n    try (\n      StreamWriter<ProjectDump.AdHocRule> output = dumpWriter.newStreamWriter(DumpElement.AD_HOC_RULES);\n      DbSession dbSession = dbClient.openSession(false);\n      Cursor<RuleDto> ruleDtoCursor = dbClient.projectExportDao()\n        .scrollAdhocRulesForExport(dbSession, projectHolder.projectDto().getUuid())) {\n      ProjectDump.AdHocRule.Builder adHocRuleBuilder = ProjectDump.AdHocRule.newBuilder();\n      ruleDtoCursor\n        .forEach(ruleDto -> {\n          ProjectDump.AdHocRule rule = convertToAdHocRule(ruleDto, adHocRuleBuilder);\n          output.write(rule);\n          count.getAndInc();\n        });\n      LoggerFactory.getLogger(getClass()).debug(\"{} ad-hoc rules exported\", count.value);\n\n    } catch (Exception e) {\n      throw new IllegalStateException(format(\"Ad-hoc rules export failed after processing %d rules successfully\", count.value), e);\n    }\n  }\n\n  private static ProjectDump.AdHocRule convertToAdHocRule(RuleDto ruleDto, ProjectDump.AdHocRule.Builder builder) {\n    CleanCodeAttribute cleanCodeAttribute = ruleDto.getCleanCodeAttribute();\n    return builder\n      .clear()\n      .setRef(ruleDto.getUuid())\n      .setPluginKey(Optional.of(ruleDto).map(RuleDto::getPluginKey).orElse(\"\"))\n      .setPluginRuleKey(ruleDto.getKey().rule())\n      .setPluginName(ruleDto.getRepositoryKey())\n      .setName(Optional.of(ruleDto).map(RuleDto::getName).orElse(\"\"))\n      .setStatus(Optional.of(ruleDto).map(RuleDto::getStatus).map(Enum::name).orElse(\"\"))\n      .setType(ruleDto.getType())\n      .setScope(ruleDto.getScope().name())\n      .setMetadata(buildMetadata(ruleDto))\n      .setCleanCodeAttribute(cleanCodeAttribute != null ? cleanCodeAttribute.name() : null)\n      .addAllImpacts(buildImpacts(ruleDto.getDefaultImpacts()))","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/SonarSource/sonarqube/blob/184c821202192afc1c599fc912d0889b69fffa53/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectexport/rule/ExportAdHocRulesStep.java#L54-L90","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before: streaming write can fail mid-loop\noutput.write(rule);\n// after: ensure stream/dir is writable and handle per-rule conversion issues before export\nif (!rootDir.canWrite()) { throw new IOException(\"dump dir not writable: \" + rootDir); }\noutput.write(convertToAdHocRule(ruleDto, builder));","handlingStrategy":"try-catch","validationCode":"if (!Files.isWritable(dumpRootDir)) { throw new IllegalStateException(\"Dump dir not writable\"); }","typeGuard":null,"tryCatchPattern":"try { exportStep.execute(); } catch (IllegalStateException e) { logger.error(\"Ad-hoc rule export aborted: {}\", e.getCause(), e); /* dump is invalid; do not publish */ }","preventionTips":["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"],"tags":["sonarqube","project-export","io","dump-export"],"backgroundTag":"file-write-failed","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"}