{"record":{"id":"912331863e1d97cc","repo":"SonarSource/sonarqube","slug":"fail-to-read-message-formattings-from-db-for-issue","errorCode":null,"errorMessage":"Fail to read message formattings from DB for issue %s","messagePattern":"Fail to read message formattings from DB for issue (.+?)","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectexport/issue/ExportIssuesStep.java","lineNumber":177,"sourceCode":"        builder.setLocations(ByteString.copyFrom(bytes));\n      }\n    } catch (InvalidProtocolBufferException e) {\n      throw new IllegalStateException(format(\"Fail to read locations from DB for issue %s\", issueDto.getKee()), e);\n    }\n  }\n\n  private static void setMessageFormattings(ProjectDump.Issue.Builder builder, IssueDto issueDto) {\n    try {\n      byte[] bytes = issueDto.getMessageFormattings();\n      if (bytes != null) {\n        // fail fast, ensure we can read data from DB\n        DbIssues.MessageFormattings messageFormattings = DbIssues.MessageFormattings.parseFrom(bytes);\n        if (messageFormattings != null) {\n          builder.addAllMessageFormattings(dbToDumpMessageFormatting(messageFormattings.getMessageFormattingList()));\n        }\n      }\n    } catch (InvalidProtocolBufferException e) {\n      throw new IllegalStateException(format(\"Fail to read message formattings from DB for issue %s\", issueDto.getKee()), e);\n    }\n  }\n\n  @VisibleForTesting\n  static List<ProjectDump.MessageFormatting> dbToDumpMessageFormatting(List<DbIssues.MessageFormatting> messageFormattingList) {\n    return messageFormattingList.stream()\n      .map(e -> ProjectDump.MessageFormatting.newBuilder()\n        .setStart(e.getStart())\n        .setEnd(e.getEnd())\n        .setType(ProjectDump.MessageFormattingType.valueOf(e.getType().name())).build())\n      .toList();\n  }\n\n  private static class RuleRegistrar {\n    private final RuleRepository ruleRepository;\n    private Rule previousRule = null;\n    private String previousRuleUuid = null;\n","sourceCodeStart":159,"sourceCodeEnd":195,"githubUrl":"https://github.com/SonarSource/sonarqube/blob/184c821202192afc1c599fc912d0889b69fffa53/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectexport/issue/ExportIssuesStep.java#L159-L195","documentation":"setMessageFormattings() parses the MESSAGE_FORMATTINGS protobuf column from the ISSUES row and converts it into the dump format. If the bytes cannot be parsed (InvalidProtocolBufferException), an IllegalStateException naming the issue key is thrown, aborting the issue export.","triggerScenarios":"ISSUES.MESSAGE_FORMATTINGS holds bytes that are not a valid DbIssues.MessageFormattings message — truncated write, manual edits, data written by an incompatible version, or storage corruption.","commonSituations":"Failed/partial upgrades leaving mixed-version rows; DB restores from inconsistent backups; corrupted blobs on disk; custom plugins writing non-standard data.","solutions":["Find the issue by key from the message; clear or repair its MESSAGE_FORMATTINGS value (NULL is tolerated — the code checks bytes != null) or re-run analysis to regenerate.","Restore corrupted rows from a consistent backup.","Align SonarQube versions between data producer and exporter; finish pending schema migrations.","If corruption is widespread, investigate storage integrity and DB health."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"byte[] bytes = issueDto.getMessageFormattings();\nif (bytes != null) {\n  try { DbIssues.MessageFormattings.parseFrom(bytes); } catch (InvalidProtocolBufferException e) { flagIssueAsCorrupt(issueDto.getKee()); }\n}","typeGuard":"boolean hasValidMessageFormattings(IssueDto dto) {\n  byte[] b = dto.getMessageFormattings();\n  if (b == null) return true;\n  try { DbIssues.MessageFormattings.parseFrom(b); return true; }\n  catch (InvalidProtocolBufferException e) { return false; }\n}","tryCatchPattern":"try {\n  exportIssuesStep.execute(context);\n} catch (IllegalStateException e) {\n  if (e.getCause() instanceof InvalidProtocolBufferException) {\n    logger.error(\"Corrupt message formattings blob for issue; repair or NULL the column\");\n  }\n}","preventionTips":["Set MESSAGE_FORMATTINGS to NULL rather than deleting partial data when in doubt","Complete upgrade migrations so blobs match the reader's schema","Avoid custom code writing directly to protobuf columns","Re-run analysis to regenerate invalid payloads"],"tags":["protobuf","corruption","issues","database","sonarqube"],"backgroundTag":"protobuf-unmarshal-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"}