{"record":{"id":"af7ac3487cf16068","repo":"SonarSource/sonarqube","slug":"issue-with-key-s-does-not-exist-af7ac3","errorCode":null,"errorMessage":"Issue with key '%s' does not exist","messagePattern":"Issue with key '(.+?)' does not exist","errorType":"http","errorClass":"NotFoundException","httpStatus":404,"severity":"error","filePath":"server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/IssueFinder.java","lineNumber":49,"sourceCode":"import static java.util.Objects.requireNonNull;\nimport static org.sonar.core.rule.RuleType.SECURITY_HOTSPOT;\n\npublic class IssueFinder {\n\n  private final DbClient dbClient;\n  private final UserSession userSession;\n\n  public IssueFinder(DbClient dbClient, UserSession userSession) {\n    this.dbClient = dbClient;\n    this.userSession = userSession;\n  }\n\n  public IssueDto getByKey(DbSession session, String issueKey) {\n    IssueDto issue = dbClient.issueDao().selectByKey(session, issueKey).orElseThrow(() -> new NotFoundException(format(\"Issue with key '%s' does not exist\", issueKey)));\n\n    RuleType ruleType = RuleType.valueOfNullable(issue.getType());\n    if (SECURITY_HOTSPOT.equals(ruleType)) {\n      throw new NotFoundException(format(\"Issue with key '%s' does not exist\", issueKey));\n    }\n\n    userSession.checkComponentUuidPermission(ProjectPermission.USER, requireNonNull(issue.getProjectUuid()));\n    return issue;\n  }\n\n}\n","sourceCodeStart":31,"sourceCodeEnd":57,"githubUrl":"https://github.com/SonarSource/sonarqube/blob/184c821202192afc1c599fc912d0889b69fffa53/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/IssueFinder.java#L31-L57","documentation":"Thrown by IssueFinder.getByKey when no issue exists for the given key, or when the key actually refers to a SECURITY_HOTSPOT. Hotspots are deliberately hidden from the issue APIs, producing the same NotFound message to avoid distinguishing the two cases.","triggerScenarios":"Calling api/issues/* endpoints (show, add_comment, transition, etc.) with an issue key that was deleted (bulk change, project re-scan removing issues), or with a hotspot key which is not an issue.","commonSituations":"Stale issue keys cached in CI dashboards after a full scan closed the issues; passing a hotspot key from api/hotspots/search into issue APIs; typos or truncated keys; issues purged when the project was re-analyzed with different rules.","solutions":["Re-fetch the issue with GET api/issues/search to get a current, valid key","If it is a hotspot, use api/hotspots/show and hotspot endpoints instead","Refresh any cached issue keys after each analysis","Verify the issue still exists before performing chained operations in automation"],"exampleFix":"// before\nconst issue = issues[0].key; // from an old scan\nawait post('/api/issues/add_comment', {issue, comment: 'x'});\n// after\nconst {issues} = await get('/api/issues/search', {componentKeys: 'my_project', resolved: 'false'});\nif (issues.length) await post('/api/issues/add_comment', {issue: issues[0].key, comment: 'x'});","handlingStrategy":"try-catch","validationCode":"const res = await searchIssues({issueKeys: [key]});\nif (!res.issues.length) throw new Error('issue not found or is a hotspot');","typeGuard":null,"tryCatchPattern":"try { await get('/api/issues/show', {key}); } catch (e) { if (e.status === 404) { /* key deleted or is a hotspot: refetch or use /api/hotspots/show */ } else throw e; }","preventionTips":["Refresh issue keys after each analysis","Never pass hotspot keys to issue endpoints","Check issue existence before chained operations"],"tags":["sonarqube","issues","webapi","not-found"],"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-14T05:17:10.506Z"}