{"record":{"id":"bf0096af2f15eab5","repo":"SonarSource/sonarqube","slug":"issue-with-key-s-does-not-exist","errorCode":null,"errorMessage":"Issue with key '%s' does not exist","messagePattern":"Issue with key '(.+?)' does not exist","errorType":"exception","errorClass":"org.sonar.db.RowNotFoundException","httpStatus":null,"severity":"error","filePath":"server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueDao.java","lineNumber":50,"sourceCode":"import org.sonar.db.Pagination;\nimport org.sonar.db.RowNotFoundException;\nimport org.sonar.db.component.ComponentDto;\n\nimport static com.google.common.base.Preconditions.checkState;\nimport static org.sonar.db.DatabaseUtils.executeLargeInputs;\n\npublic class IssueDao implements Dao {\n  public static final int DEFAULT_PAGE_SIZE = 1000;\n  public static final int BIG_PAGE_SIZE = 1000000;\n\n  public Optional<IssueDto> selectByKey(DbSession session, String key) {\n    return Optional.ofNullable(mapper(session).selectByKey(key));\n  }\n\n  public IssueDto selectOrFailByKey(DbSession session, String key) {\n    Optional<IssueDto> issue = selectByKey(session, key);\n    if (issue.isEmpty()) {\n      throw new RowNotFoundException(String.format(\"Issue with key '%s' does not exist\", key));\n    }\n    return issue.get();\n  }\n\n  /**\n   * Gets a list issues by their keys. The result does NOT contain {@code null} values for issues not found, so\n   * the size of result may be less than the number of keys. A single issue is returned\n   * if input keys contain multiple occurrences of a key.\n   * <p>Results may be in a different order as input keys.</p>\n   */\n  public List<IssueDto> selectByKeys(DbSession session, Collection<String> keys) {\n    return executeLargeInputs(keys, mapper(session)::selectByKeys);\n  }\n\n  public List<IssueDto> selectSourceRedactionIssues(DbSession session, String componentUuid, Collection<String> ruleKeys) {\n    return mapper(session).selectSourceRedactionIssues(componentUuid, ruleKeys);\n  }\n","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/SonarSource/sonarqube/blob/184c821202192afc1c599fc912d0889b69fffa53/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueDao.java#L32-L68","documentation":"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.","triggerScenarios":"Calling selectOrFailByKey with a key string that is not present in the ISSUES table (typo, deleted issue, wrong component key, or issue purged).","commonSituations":"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.","solutions":["Verify the issue key is correct and the issue still exists","Use selectByKey (Optional) when absence is an expected outcome","Check whether the issue was deleted or the branch was removed","Handle RowNotFoundException and return a 404 to the API caller"],"exampleFix":"// before\nIssueDto dto = issueDao.selectOrFailByKey(dbSession, key);\n// after\nOptional<IssueDto> dto = issueDao.selectByKey(dbSession, key);\nif (dto.isEmpty()) {\n  // fall back / inform user instead of throwing\n}","handlingStrategy":"try-catch","validationCode":"if (key == null || key.isBlank()) {\n  throw new IllegalArgumentException(\"Issue key is required\");\n}\nif (issueDao.selectByKey(dbSession, key).isEmpty()) {\n  throw new IllegalArgumentException(\"Issue \" + key + \" not found\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  IssueDto issue = issueDao.selectOrFailByKey(dbSession, key);\n} catch (RowNotFoundException e) {\n  // return 404 / fallback handling\n}","preventionTips":["Prefer selectByKey (Optional) when absence is expected","Validate issue keys come from a recent query, not stale clients","Account for issue deletion and branch removal before dereferencing keys","Never confuse component key with issue key"],"tags":["database","not-found","issues"],"backgroundTag":"record-not-found","analyzedSha":"184c821202192afc1c599fc912d0889b69fffa53","analyzedAt":"2026-09-09T12:23:51.573Z","contentChangedAt":"2026-09-09T12:23:51.573Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}