SonarSource/sonarqube · error · IllegalStateException

Fail to read locations from DB for issue %s

Error message

Fail to read locations from DB for issue %s

What it means

setLocations() deliberately parses the raw LOCATIONS protobuf bytes from the ISSUES row before copying them into the dump, to fail fast on corrupt data. If DbIssues.Locations.parseFrom throws InvalidProtocolBufferException, the error is wrapped in an IllegalStateException naming the issue key.

Source

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

      .forEach(builder::addImpacts);
  }

  private String registerRule(IssueDto issueDto) {
    String ruleUuid = issueDto.getRuleUuid();
    RuleKey ruleKey = issueDto.getRuleKey();
    return ruleRegistrar.register(ruleUuid, ruleKey).ref();
  }

  private static void setLocations(ProjectDump.Issue.Builder builder, IssueDto issueDto) {
    try {
      byte[] bytes = issueDto.getLocations();
      if (bytes != null) {
        // fail fast, ensure we can read data from DB
        DbIssues.Locations.parseFrom(bytes);
        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);
    }
  }

View on GitHub (pinned to 184c821202)

Solutions

  1. Identify the issue by its key (in the message) and inspect its LOCATIONS blob; delete or repair the row (e.g. re-run analysis to rewrite issue data).
  2. Restore the affected rows from a consistent DB backup if corruption is widespread.
  3. Verify the SonarQube version that wrote the data matches the one exporting it; complete pending migrations.
  4. Check storage integrity if many rows fail protobuf parsing.
Defensive patterns

Strategy: try-catch

Validate before calling

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

Type guard

boolean hasValidLocations(IssueDto dto) {
  byte[] b = dto.getLocations();
  if (b == null) return true;
  try { DbIssues.Locations.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 locations blob; skip or repair issue data");
  }
}

Prevention

When it happens

Trigger: ISSUES.LOCATIONS column contains bytes that are not a valid DbIssues.Locations protobuf — e.g. truncated row, manual DB edits, data written by an incompatible SonarQube version, or encoding corruption.

Common situations: Partial/failed SonarQube upgrades; restoring a DB backup inconsistent with the schema; storage-level corruption; cross-version data migrations.

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/66ab9b224147aacd. Report an issue: GitHub.