SonarSource/sonarqube · error · org.sonar.db.RowNotFoundException

Issue with key ' ' does not exist

Error message

Issue with key '%s' does not exist

What it means

IssueDao.selectOrFailByKey throws RowNotFoundException when no issue row matches the given key, in cases where the caller requires the issue to exist. It is the strict counterpart of selectByKey which returns an Optional.

Solutions

  1. Verify the issue key is correct and the issue still exists
  2. Use selectByKey (Optional) when absence is an expected outcome
  3. Check whether the issue was deleted or the branch was removed
  4. Handle RowNotFoundException and return a 404 to the API caller

Example fix

// before
IssueDto dto = issueDao.selectOrFailByKey(dbSession, key);
// after
Optional<IssueDto> dto = issueDao.selectByKey(dbSession, key);
if (dto.isEmpty()) {
  // fall back / inform user instead of throwing
}
Defensive patterns

Strategy: try-catch

Validate before calling

if (key == null || key.isBlank()) {
  throw new IllegalArgumentException("Issue key is required");
}
if (issueDao.selectByKey(dbSession, key).isEmpty()) {
  throw new IllegalArgumentException("Issue " + key + " not found");
}

Try / catch

try {
  IssueDto issue = issueDao.selectOrFailByKey(dbSession, key);
} catch (RowNotFoundException e) {
  // return 404 / fallback handling
}

Prevention

When it happens

Trigger: Calling selectOrFailByKey with a key string that is not present in the ISSUES table (typo, deleted issue, wrong component key, or issue purged).

Common situations: Web API operations on stale issue keys after issue deletion/closure; references to issues from another branch; bugs passing component key instead of issue key; data cleaned by housekeeping.

Understand the failure class

Background: Record Not Found Errors: "not found", RecordNotFound, and "was not found" — what they mean and how to fix them — this error's family across 28 libraries.

Related errors


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

Appendix: source

Thrown at server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueDao.java:50

import org.sonar.db.Pagination;
import org.sonar.db.RowNotFoundException;
import org.sonar.db.component.ComponentDto;

import static com.google.common.base.Preconditions.checkState;
import static org.sonar.db.DatabaseUtils.executeLargeInputs;

public class IssueDao implements Dao {
  public static final int DEFAULT_PAGE_SIZE = 1000;
  public static final int BIG_PAGE_SIZE = 1000000;

  public Optional<IssueDto> selectByKey(DbSession session, String key) {
    return Optional.ofNullable(mapper(session).selectByKey(key));
  }

  public IssueDto selectOrFailByKey(DbSession session, String key) {
    Optional<IssueDto> issue = selectByKey(session, key);
    if (issue.isEmpty()) {
      throw new RowNotFoundException(String.format("Issue with key '%s' does not exist", key));
    }
    return issue.get();
  }

  /**
   * Gets a list issues by their keys. The result does NOT contain {@code null} values for issues not found, so
   * the size of result may be less than the number of keys. A single issue is returned
   * if input keys contain multiple occurrences of a key.
   * <p>Results may be in a different order as input keys.</p>
   */
  public List<IssueDto> selectByKeys(DbSession session, Collection<String> keys) {
    return executeLargeInputs(keys, mapper(session)::selectByKeys);
  }

  public List<IssueDto> selectSourceRedactionIssues(DbSession session, String componentUuid, Collection<String> ruleKeys) {
    return mapper(session).selectSourceRedactionIssues(componentUuid, ruleKeys);
  }

View on GitHub (pinned to 184c821202)