{"record":{"id":"5448647a6854b843","repo":"SonarSource/sonarqube","slug":"project-s-for-branch-s-not-found","errorCode":null,"errorMessage":"Project '%s' for branch '%s' not found","messagePattern":"Project '(.+?)' for branch '(.+?)' not found","errorType":"exception","errorClass":"IllegalStateException","httpStatus":500,"severity":"error","filePath":"server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/history/controller/ProjectCollectionContextLoader.java","lineNumber":120,"sourceCode":"    List<ProjectBranch> branches = branchDtos.stream()\n      .map(branch -> toProjectBranch(branch, projectsByUuid))\n      .toList();\n    Set<String> visibleProjectUuids = userSession.keepAuthorizedEntities(USER, projects).stream()\n      .map(ProjectDto::getUuid)\n      .collect(Collectors.toSet());\n    Set<String> visibleBranchIds = branchDtos.stream()\n      .filter(branch -> visibleProjectUuids.contains(branch.getProjectUuid()))\n      .map(BranchDto::getUuid)\n      .collect(Collectors.toSet());\n    return new ProjectCollectionContext(branches, visibleBranchIds);\n  }\n\n  private static ProjectBranch toProjectBranch(\n    BranchDto branch,\n    Map<String, ProjectDto> projectsByUuid) {\n    ProjectDto project = projectsByUuid.get(branch.getProjectUuid());\n    if (project == null) {\n      throw new IllegalStateException(\"Project '%s' for branch '%s' not found\"\n        .formatted(branch.getProjectUuid(), branch.getUuid()));\n    }\n    return new ProjectBranch(\n      branch.getUuid(), branch.getKey(), project.getKey(), project.getName());\n  }\n\n  private static NotFoundException contextNotFound(String contextId) {\n    return new NotFoundException(\"Portfolio or application branch '%s' not found\".formatted(contextId));\n  }\n}\n","sourceCodeStart":102,"sourceCodeEnd":131,"githubUrl":"https://github.com/SonarSource/sonarqube/blob/184c821202192afc1c599fc912d0889b69fffa53/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/history/controller/ProjectCollectionContextLoader.java#L102-L131","documentation":"IllegalStateException thrown by ProjectCollectionContextLoader.toProjectBranch when a BranchDto references a projectUuid that has no matching entry in the projectsByUuid map loaded by the caller (branches). This is an internal consistency check: every branch row in SonarQube must point at an existing project row, so a miss indicates corrupt or concurrently-deleted data rather than a caller mistake.","triggerScenarios":"Calling the project history/branches Web API v2 endpoint while a project referenced by a branch has been deleted (or its rows are inconsistent) between the branch query and the project lookup; the branch's project_uuid matches no ProjectDto uuid.","commonSituations":"Database in an inconsistent state after a partial project deletion, a failed migration, manual DB manipulation, or a race where the project is removed while branches are still listed.","solutions":["Verify database integrity: confirm the project row for the branch's project_uuid exists in the PROJECTS table","Re-run or repair the failed deletion/migration that left orphaned branches","Delete the orphaned branch rows referencing the missing project","Retry the request once a consistent database state is restored; upgrade SonarQube if a known bug fixed this"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// Java client\ntry {\n    List<ProjectBranch> branches = api.getProjectHistoryBranches();\n} catch (ServerErrorException e) { // 500 mapped from IllegalStateException\n    // treat as transient/DB inconsistency: log branch context, back off, retry once\n}","preventionTips":["Avoid deleting projects while consuming the branches/history API concurrently","Keep SonarQube upgraded to get DB-consistency fixes","Monitor for orphaned branch rows after bulk deletions"],"tags":["java","database","inconsistent-state"],"backgroundTag":"internal-invariant-violation","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"}