{"record":{"id":"780051b407f30740","repo":"SonarSource/sonarqube","slug":"component-s-on-branch-s-not-found","errorCode":null,"errorMessage":"Component '%s' on branch '%s' not found","messagePattern":"Component '(.+?)' on branch '(.+?)' not found","errorType":"http","errorClass":"NotFoundException","httpStatus":404,"severity":"error","filePath":"server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ComponentFinder.java","lineNumber":254,"sourceCode":"        rootQualifiers.contains(ComponentQualifiers.VIEW) ? \" or a view\" : \"\"));\n\n    return component;\n  }\n\n  private static Set<String> getRootQualifiers(ComponentTypes componentTypes) {\n    Collection<ComponentType> rootTypes = componentTypes.getRoots();\n    return rootTypes\n      .stream()\n      .map(ComponentType::getQualifier)\n      .collect(Collectors.toSet());\n  }\n\n  public ComponentDto getByKeyAndBranch(DbSession dbSession, String key, String branch) {\n    Optional<ComponentDto> componentDto = dbClient.componentDao().selectByKeyAndBranch(dbSession, key, branch);\n    if (componentDto.isPresent() && componentDto.get().isEnabled()) {\n      return componentDto.get();\n    }\n    throw new NotFoundException(format(\"Component '%s' on branch '%s' not found\", key, branch));\n  }\n\n  public ComponentDto getByKeyAndPullRequest(DbSession dbSession, String key, String pullRequest) {\n    Optional<ComponentDto> componentDto = dbClient.componentDao().selectByKeyAndPullRequest(dbSession, key, pullRequest);\n    if (componentDto.isPresent() && componentDto.get().isEnabled()) {\n      return componentDto.get();\n    }\n    throw new NotFoundException(format(\"Component '%s' of pull request '%s' not found\", key, pullRequest));\n  }\n\n  public ComponentDto getByKeyAndOptionalBranchOrPullRequest(DbSession dbSession, String key, @Nullable String branch, @Nullable String pullRequest) {\n    checkArgument(branch == null || pullRequest == null, \"Either branch or pull request can be provided, not both\");\n    if (branch != null) {\n      return getByKeyAndBranch(dbSession, key, branch);\n    } else if (pullRequest != null) {\n      return getByKeyAndPullRequest(dbSession, key, pullRequest);\n    }\n    return getByKey(dbSession, key);","sourceCodeStart":236,"sourceCodeEnd":272,"githubUrl":"https://github.com/SonarSource/sonarqube/blob/184c821202192afc1c599fc912d0889b69fffa53/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ComponentFinder.java#L236-L272","documentation":"getByKeyAndBranch fetches a component by component key plus branch name; if no row matches, or the component is disabled, it throws NotFoundException 'Component '<key>' on branch '<branch>' not found'.","triggerScenarios":"api/components/show or similar with a component=<key>&branch=<branch> pair where the branch does not exist for that component, or the component was disabled/deleted on that branch.","commonSituations":"Branch deleted after merge; typo in branch name or key; component (file/module) removed from the branch in the latest analysis; branch name needing URL encoding (e.g. feature/x).","solutions":["List valid branches via api/project_branches/list and use an exact branch name","Check the component key exists on that branch (api/components/search with branch param)","Re-run analysis to repopulate the component if it was removed","URL-encode branch names containing '/' or special characters"],"exampleFix":"// before\nGET /api/components/show?component=foo&branch=feature/x\n// after\nGET /api/project_branches/list?project=foo   // find exact branch key\nGET /api/components/show?component=foo&branch=feature%2Fx","handlingStrategy":"validation","validationCode":"const branches = await api.branches.list({ project: key });\nif (!branches.some(b => b.name === branchName)) {\n  throw new Error(`branch '${branchName}' does not exist for ${key}`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  return await api.components.show({ component: key, branch: branch });\n} catch (e) {\n  if (e.status === 404 && /on branch .* not found/.test(e.message)) {\n    return null; // fall back to main-branch data\n  }\n  throw e;\n}","preventionTips":["Fetch branch names from api/project_branches/list, never hardcode","URL-encode branch names containing '/'","Check component existence on the branch with api/components/search?branch=...","Handle branch auto-deletion after PR merge"],"tags":["java","components","branches","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"}