{"record":{"id":"c148299ac7d325d5","repo":"SonarSource/sonarqube","slug":"quality-profile-not-found-s","errorCode":null,"errorMessage":"Quality profile not found: %s","messagePattern":"Quality profile not found: (.+?)","errorType":"http","errorClass":"NotFoundException","httpStatus":404,"severity":"error","filePath":"server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/ProjectsAction.java","lineNumber":127,"sourceCode":"        .collect(Collectors.toSet());\n\n      Set<String> authorizedProjectUuids = dbClient.authorizationDao().keepAuthorizedEntityUuids(session, projectUuids, userSession.getUuid(), ProjectPermission.USER);\n      Paging paging = forPageIndex(page).withPageSize(pageSize).andTotal(authorizedProjectUuids.size());\n\n      List<ProjectQprofileAssociationDto> authorizedProjects = projects.stream()\n        .filter(input -> authorizedProjectUuids.contains(input.getProjectUuid()))\n        .skip(paging.offset())\n        .limit(paging.pageSize())\n        .toList();\n\n      writeProjects(response, authorizedProjects, paging);\n    }\n  }\n\n  private List<ProjectQprofileAssociationDto> loadAllProjects(String profileKey, DbSession session, String selected, String query) {\n    QProfileDto profile = dbClient.qualityProfileDao().selectByUuid(session, profileKey);\n    if (profile == null) {\n      throw new NotFoundException(\"Quality profile not found: \" + profileKey);\n    }\n    List<ProjectQprofileAssociationDto> projects;\n    SelectionMode selectionMode = SelectionMode.fromParam(selected);\n\n    projects = switch (selectionMode) {\n      case SELECTED -> dbClient.qualityProfileDao().selectSelectedProjects(session, profile, query);\n      case DESELECTED -> dbClient.qualityProfileDao().selectDeselectedProjects(session, profile, query);\n      case null, default -> dbClient.qualityProfileDao().selectProjectAssociations(session, profile, query);\n    };\n\n    return projects;\n  }\n\n  private static void writeProjects(Response response, List<ProjectQprofileAssociationDto> projects, Paging paging) {\n    JsonWriter json = response.newJsonWriter();\n\n    json.beginObject();\n    json.name(\"results\").beginArray();","sourceCodeStart":109,"sourceCodeEnd":145,"githubUrl":"https://github.com/SonarSource/sonarqube/blob/184c821202192afc1c599fc912d0889b69fffa53/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/ProjectsAction.java#L109-L145","documentation":"ProjectsAction.loadAllProjects looks up the quality profile by UUID before listing its projects; when qualityProfileDao().selectByUuid returns null the profile key does not exist, so a NotFoundException with the offending key is raised. This is a guard against listing projects of a nonexistent profile.","triggerScenarios":"Calling api/qualityprofiles/projects with a 'key' parameter that matches no profile: mistyped key, profile already deleted, or a key copied from another SonarQube instance.","commonSituations":"Automation holding stale profile keys after a profile was deleted or re-created (keys/UUIDs change on re-creation); case/whitespace errors in the key; querying the wrong server environment.","solutions":["Call api/qualityprofiles/search and use the exact 'key' field from the response","Check the profile still exists (it may have been deleted or renamed since the key was captured)","Refresh cached/stored profile keys in your automation after any profile modification"],"exampleFix":"// before\ncurl api/qualityprofiles/projects?key=java-my-old-profile\n// after\nKEY=$(curl api/qualityprofiles/search?language=java | jq -r '.profiles[] | select(.name==\"My Profile\") | .key')\ncurl \"api/qualityprofiles/projects?key=$KEY\"","handlingStrategy":"validation","validationCode":"const search = await get(\"api/qualityprofiles/search\");\nconst exists = search.profiles.some(p => p.key === profileKey);\nif (!exists) throw new Error(`Unknown profile key: ${profileKey}`);","typeGuard":"function assertProfileExists(profiles, key) {\n  const p = profiles.find(x => x.key === key);\n  if (!p) throw new Error(`Quality profile not found: ${key}`);\n  return p;\n}","tryCatchPattern":"try {\n  return await get(`api/qualityprofiles/projects?key=${encodeURIComponent(key)}`);\n} catch (err) {\n  if (err.status === 404 && String(err.body).includes(\"Quality profile not found\")) {\n    throw new Error(`Stale profile key '${key}' — re-fetch via api/qualityprofiles/search`);\n  }\n  throw err;\n}","preventionTips":["Fetch profile keys dynamically via api/qualityprofiles/search instead of hard-coding","Invalidate cached keys whenever a profile is deleted or re-created","Trim and copy keys exactly as returned by the API (they are UUID-like)"],"tags":["sonarqube","quality-profile","not-found","web-api"],"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-17T15:17:12.973Z"}