{"record":{"id":"d70848f8d45339ac","repo":"SonarSource/sonarqube","slug":"project-has-not-been-found","errorCode":null,"errorMessage":"Project has not been found","messagePattern":"Project has not been found","errorType":"exception","errorClass":"NotFoundException","httpStatus":404,"severity":"error","filePath":"server/sonar-webserver-webapi/src/main/java/org/sonar/server/badge/ws/ProjectBadgesSupport.java","lineNumber":92,"sourceCode":"        \"Project badge token. Required for private projects or if the 'sonar.forceAuthentication' setting is enabled.\"\n      )\n      .setExampleValue(PROJECT_BADGE_TOKEN_EXAMPLE);\n  }\n\n  BranchDto getBranch(DbSession dbSession, Request request) {\n    try {\n      String branchName = request.param(PARAM_BRANCH);\n      ProjectDto project = getProject(dbSession, request);\n\n      BranchDto branch = componentFinder.getBranchOrPullRequest(dbSession, project, branchName, null);\n\n      if (!branch.getBranchType().equals(BRANCH)) {\n        throw generateInvalidProjectException();\n      }\n\n      return branch;\n    } catch (NotFoundException e) {\n      throw new NotFoundException(PROJECT_HAS_NOT_BEEN_FOUND);\n    }\n  }\n\n  public ProjectDto getProject(DbSession dbSession, Request request) {\n    String projectKey = request.mandatoryParam(PARAM_PROJECT);\n    return componentFinder.getProjectOrApplicationByKey(dbSession, projectKey);\n  }\n\n  private static ProjectBadgesException generateInvalidProjectException() {\n    return new ProjectBadgesException(\"Project is invalid\");\n  }\n\n  public void validateToken(Request request) {\n    try (DbSession dbSession = dbClient.openSession(false)) {\n      String projectKey = request.mandatoryParam(PARAM_PROJECT);\n      ProjectDto projectDto;\n      try {\n        projectDto = componentFinder.getProjectOrApplicationByKey(dbSession, projectKey);","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/SonarSource/sonarqube/blob/184c821202192afc1c599fc912d0889b69fffa53/server/sonar-webserver-webapi/src/main/java/org/sonar/server/badge/ws/ProjectBadgesSupport.java#L74-L110","documentation":"The badge web service's getBranch looks up the project/application and its main branch; if the component is not found (NotFoundException from the component finder) or the found branch is not a BRANCH type, it is rethrown as this generic NotFoundException. Sonar deliberately returns 404 'Project has not been found' instead of revealing whether the project exists.","triggerScenarios":"Calling any badge WS endpoint (e.g. api/project_badges/measure) with a 'project' parameter whose key matches no project/application, or the key points at a non-BRANCH component like a portfoli; also when the anonymous caller cannot see a private project.","commonSituations":"Stale badge URLs after project key rename/deletion; wrong project key in README badge markdown; querying a private project without token while unauthenticated.","solutions":["Check the project key in the badge URL matches an existing SonarQube project key","If the project was renamed, update the badge URL with the new key","Ensure the project/application exists and is visible (public, or valid token supplied)","Confirm the component type — badges only work for projects/applications, not portfolios"],"exampleFix":"// before\n[![Quality Gate](https://sonar.example.com/api/project_badges/measure?project=old-key)]\n// after\n[![Quality Gate](https://sonar.example.com/api/project_badges/measure?project=new-key)]","handlingStrategy":"validation","validationCode":"// Before embedding/rendering a badge, check the project key exists and is visible:\nconst res = await fetch(`${sonarUrl}/api/components/show?component=${encodeURIComponent(projectKey)}`);\nif (!res.ok) {\n  throw new Error(`Project key '${projectKey}' not found on ${sonarUrl}; update the badge URL`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  badge = fetchBadgeSvg(projectKey);\n} catch (err) {\n  if (err.status === 404 && /Project has not been found/.test(err.body)) {\n    // verify key on the server, fall back to a placeholder badge\n    badge = renderPlaceholderBadge();\n  } else { throw err; }\n}","preventionTips":["Regenerate badge URLs from SonarQube's project page instead of copying old ones","Update badges after any project key rename","Confirm the project exists on the exact server host used in the badge URL","For private projects, always supply a valid badge token"],"tags":["badges","not-found","webapi","project-key"],"backgroundTag":"resource-not-found","analyzedSha":"184c821202192afc1c599fc912d0889b69fffa53","analyzedAt":"2026-09-09T12:23:51.573Z","contentChangedAt":"2026-09-09T12:23:51.573Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}