{"record":{"id":"c09bab5f7f6577a4","repo":"SonarSource/sonarqube","slug":"e-getmessage","errorCode":null,"errorMessage":"e.getMessage()","messagePattern":"e\\.getMessage\\(\\)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"server/sonar-alm-client/src/main/java/org/sonar/alm/client/bitbucket/bitbucketcloud/BitbucketCloudRestClient.java","lineNumber":111,"sourceCode":"\n  /**\n   * Validate parameters provided.\n   */\n  public void validate(String clientId, String clientSecret, String workspace) {\n    Token token = validateAccessToken(clientId, clientSecret);\n\n    if (token.getScope() == null || !token.getScope().contains(\"pullrequest\")) {\n      LOG.atInfo()\n        .addArgument(MISSING_PULL_REQUEST_READ_PERMISSION)\n        .addArgument(() -> String.format(SCOPE, token.getScope()))\n        .log(\"{}{}\");\n      throw new IllegalArgumentException(ERROR_BBC_SERVERS + \": \" + MISSING_PULL_REQUEST_READ_PERMISSION);\n    }\n\n    try {\n      doGet(token.getAccessToken(), buildUrl(\"/repositories/\" + workspace), r -> null);\n    } catch (NotFoundException | IllegalStateException | BitbucketCloudException e) {\n      throw new IllegalArgumentException(e.getMessage());\n    }\n  }\n\n  /**\n   * Validate parameters provided.\n   */\n  public void validateApiToken(String encodedApiTokenCredentials, String workspace) {\n    try {\n      doGetWithApiToken(encodedApiTokenCredentials, buildUrl(\"/repositories/\" + workspace), r -> null);\n    } catch (NotFoundException | IllegalStateException e) {\n      throw new IllegalArgumentException(e.getMessage());\n    }\n  }\n\n  private Token validateAccessToken(String clientId, String clientSecret) {\n    Request request = createAccessTokenRequest(clientId, clientSecret);\n    try (Response response = client.newCall(request).execute()) {\n      if (response.isSuccessful()) {","sourceCodeStart":93,"sourceCodeEnd":129,"githubUrl":"https://github.com/SonarSource/sonarqube/blob/184c821202192afc1c599fc912d0889b69fffa53/server/sonar-alm-client/src/main/java/org/sonar/alm/client/bitbucket/bitbucketcloud/BitbucketCloudRestClient.java#L93-L129","documentation":"After the scope check passes, validate probes the workspace by GETting /repositories/{workspace}; if that call throws NotFoundException, IllegalStateException or BitbucketCloudException, the client rethrows IllegalArgumentException wrapping only e.getMessage(). This surfaces 'workspace not found' (404), auth/scope failures, or other Bitbucket API errors as the validation failure message.","triggerScenarios":"validate(clientId, clientSecret, workspace) where the workspace string doesn't exist in Bitbucket Cloud (NotFoundException), the response handling fails (IllegalStateException), or the API returns an error status (BitbucketCloudException).","commonSituations":"Typo in the workspace slug (or using the display name instead of the slug); workspace renamed or deleted; OAuth consumer lacking access to a private workspace; transient Bitbucket API 5xx.","solutions":["Check the message to distinguish the case: 'not found' means fix the workspace slug; 401/403 means check OAuth permissions.","Use the exact workspace slug from the repository URL (https://bitbucket.org/{workspace}/...), not the display name.","Confirm the OAuth consumer has access to that workspace (it belongs to the workspace where the consumer is defined).","Retry if the underlying error was a transient 5xx from Bitbucket Cloud."],"exampleFix":"// before\nvalidate(clientId, clientSecret, \"My Workspace\");\n\n// after\nvalidate(clientId, clientSecret, \"my-workspace\");","handlingStrategy":"validation","validationCode":"// Validate the workspace slug before calling validate:\nif (workspace == null || !workspace.matches(\"[a-zA-Z0-9_-]+\")) {\n  throw new IllegalArgumentException(\"Workspace must be the Bitbucket slug (e.g. 'my-workspace')\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  bbClient.validate(clientId, clientSecret, workspace);\n} catch (IllegalArgumentException e) {\n  LOG.warn(\"Bitbucket Cloud validation failed: {}\", e.getMessage());\n  // 'Not Found' -> fix workspace slug; 401/403 -> fix OAuth permissions\n}","preventionTips":["Copy the workspace slug directly from the bitbucket.org repository URL.","Use the slug, not the workspace display name.","Ensure the OAuth consumer is defined in the same workspace it accesses.","Retry transient 5xx failures with backoff."],"tags":["bitbucket-cloud","workspace","validation","http-error-response"],"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-14T05:17:10.506Z"}