SonarSource/sonarqube · error · IllegalStateException

Fail to read message formattings from DB for issue %s

Error message

Fail to read message formattings from DB for issue %s

What it means

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.

Source

Thrown at server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectexport/issue/ExportIssuesStep.java:177

        builder.setLocations(ByteString.copyFrom(bytes));
      }
    } catch (InvalidProtocolBufferException e) {
      throw new IllegalStateException(format("Fail to read locations from DB for issue %s", issueDto.getKee()), e);
    }
  }

  private static void setMessageFormattings(ProjectDump.Issue.Builder builder, IssueDto issueDto) {
    try {
      byte[] bytes = issueDto.getMessageFormattings();
      if (bytes != null) {
        // fail fast, ensure we can read data from DB
        DbIssues.MessageFormattings messageFormattings = DbIssues.MessageFormattings.parseFrom(bytes);
        if (messageFormattings != null) {
          builder.addAllMessageFormattings(dbToDumpMessageFormatting(messageFormattings.getMessageFormattingList()));
        }
      }
    } catch (InvalidProtocolBufferException e) {
      throw new IllegalStateException(format("Fail to read message formattings from DB for issue %s", issueDto.getKee()), e);
    }
  }

  @VisibleForTesting
  static List<ProjectDump.MessageFormatting> dbToDumpMessageFormatting(List<DbIssues.MessageFormatting> messageFormattingList) {
    return messageFormattingList.stream()
      .map(e -> ProjectDump.MessageFormatting.newBuilder()
        .setStart(e.getStart())
        .setEnd(e.getEnd())
        .setType(ProjectDump.MessageFormattingType.valueOf(e.getType().name())).build())
      .toList();
  }

  private static class RuleRegistrar {
    private final RuleRepository ruleRepository;
    private Rule previousRule = null;
    private String previousRuleUuid = null;

View on GitHub (pinned to 184c821202)

Solutions

  1. 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.
  2. Restore corrupted rows from a consistent backup.
  3. Align SonarQube versions between data producer and exporter; finish pending schema migrations.
  4. If corruption is widespread, investigate storage integrity and DB health.
Defensive patterns

Strategy: try-catch

Validate before calling

byte[] bytes = issueDto.getMessageFormattings();
if (bytes != null) {
  try { DbIssues.MessageFormattings.parseFrom(bytes); } catch (InvalidProtocolBufferException e) { flagIssueAsCorrupt(issueDto.getKee()); }
}

Type guard

boolean hasValidMessageFormattings(IssueDto dto) {
  byte[] b = dto.getMessageFormattings();
  if (b == null) return true;
  try { DbIssues.MessageFormattings.parseFrom(b); return true; }
  catch (InvalidProtocolBufferException e) { return false; }
}

Try / catch

try {
  exportIssuesStep.execute(context);
} catch (IllegalStateException e) {
  if (e.getCause() instanceof InvalidProtocolBufferException) {
    logger.error("Corrupt message formattings blob for issue; repair or NULL the column");
  }
}

Prevention

When it happens

Trigger: 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.

Common situations: Failed/partial upgrades leaving mixed-version rows; DB restores from inconsistent backups; corrupted blobs on disk; custom plugins writing non-standard data.

Understand the failure class

Background: "cannot parse invalid wire-format data", "cannot unmarshal", "failed unmarshalling": protobuf unmarshal errors explained — this error's family across 10 libraries.

Related errors


AI-assisted analysis of SonarSource/sonarqube@184c821202 (2026-09-09). Data as JSON: /api/errors/912331863e1d97cc. Report an issue: GitHub.