SonarSource/sonarqube · error · IllegalArgumentException

e.getMessage()

Error message

e.getMessage()

What it means

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.

Source

Thrown at server/sonar-alm-client/src/main/java/org/sonar/alm/client/bitbucket/bitbucketcloud/BitbucketCloudRestClient.java:111

  /**
   * Validate parameters provided.
   */
  public void validate(String clientId, String clientSecret, String workspace) {
    Token token = validateAccessToken(clientId, clientSecret);

    if (token.getScope() == null || !token.getScope().contains("pullrequest")) {
      LOG.atInfo()
        .addArgument(MISSING_PULL_REQUEST_READ_PERMISSION)
        .addArgument(() -> String.format(SCOPE, token.getScope()))
        .log("{}{}");
      throw new IllegalArgumentException(ERROR_BBC_SERVERS + ": " + MISSING_PULL_REQUEST_READ_PERMISSION);
    }

    try {
      doGet(token.getAccessToken(), buildUrl("/repositories/" + workspace), r -> null);
    } catch (NotFoundException | IllegalStateException | BitbucketCloudException e) {
      throw new IllegalArgumentException(e.getMessage());
    }
  }

  /**
   * Validate parameters provided.
   */
  public void validateApiToken(String encodedApiTokenCredentials, String workspace) {
    try {
      doGetWithApiToken(encodedApiTokenCredentials, buildUrl("/repositories/" + workspace), r -> null);
    } catch (NotFoundException | IllegalStateException e) {
      throw new IllegalArgumentException(e.getMessage());
    }
  }

  private Token validateAccessToken(String clientId, String clientSecret) {
    Request request = createAccessTokenRequest(clientId, clientSecret);
    try (Response response = client.newCall(request).execute()) {
      if (response.isSuccessful()) {

View on GitHub (pinned to 184c821202)

Solutions

  1. Check the message to distinguish the case: 'not found' means fix the workspace slug; 401/403 means check OAuth permissions.
  2. Use the exact workspace slug from the repository URL (https://bitbucket.org/{workspace}/...), not the display name.
  3. Confirm the OAuth consumer has access to that workspace (it belongs to the workspace where the consumer is defined).
  4. Retry if the underlying error was a transient 5xx from Bitbucket Cloud.

Example fix

// before
validate(clientId, clientSecret, "My Workspace");

// after
validate(clientId, clientSecret, "my-workspace");
Defensive patterns

Strategy: validation

Validate before calling

// Validate the workspace slug before calling validate:
if (workspace == null || !workspace.matches("[a-zA-Z0-9_-]+")) {
  throw new IllegalArgumentException("Workspace must be the Bitbucket slug (e.g. 'my-workspace')");
}

Try / catch

try {
  bbClient.validate(clientId, clientSecret, workspace);
} catch (IllegalArgumentException e) {
  LOG.warn("Bitbucket Cloud validation failed: {}", e.getMessage());
  // 'Not Found' -> fix workspace slug; 401/403 -> fix OAuth permissions
}

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


AI-assisted analysis of SonarSource/sonarqube@184c821202 (2026-09-09). Data as JSON: /api/errors/c09bab5f7f6577a4. Report an issue: GitHub.