SonarSource/sonarqube · warning
Failed to count bitbucket_cloud repos for ALM setting
Error message
Failed to count bitbucket_cloud repos for ALM setting '{}' What it means
BitbucketCloud repo counting calls createAccessToken with clientId/clientSecret then searchReposWithAccessToken to fetch a 1-item page and read its size. Any exception (OAuth failure, workspace error, HTTP error) is logged as this warning with the setting key and yields an empty count.
Solutions
- Verify the OAuth client id/secret on the bitbucket_cloud ALM setting and re-authorize
- Check the attached exception for the Bitbucket API error (401/403/404/429)
- Confirm the workspace name still exists and the OAuth consumer can access it
- Test network connectivity to api.bitbucket.org from the SonarQube host
Defensive patterns
Strategy: fallback
Validate before calling
if (clientId == null || clientSecret == null || workspace == null || workspace.isBlank()) return OptionalLong.empty();
Type guard
Integer size = repoList != null ? repoList.getSize() : null; if (size == null) return OptionalLong.empty();
Try / catch
try { ... } catch (Exception e) { LOG.warn("Failed to count bitbucket_cloud repos for ALM setting '{}'", key, e); return OptionalLong.empty(); } Prevention
- Keep Bitbucket OAuth client credentials current
- Confirm workspace name and consumer access after workspace changes
- Add backoff for Bitbucket rate limits
When it happens
Trigger: fetchTotalCount for a bitbucket_cloud provider throws during token creation or repo search for the given ALM setting key; also when repoList or its size is null.
Common situations: Invalid/rotated Bitbucket Cloud OAuth client credentials; workspace renamed or access removed; Bitbucket API outages or rate limits; egress blocked to api.bitbucket.org.
Related errors
- Can not get Bitbucket user profile. HTTP code
- Error returned by Bitbucket Cloud
- Error returned by Bitbucket Cloud: The OAuth client in the…
- Unable to contact Bitbucket Cloud servers
- Unable to contact Bitbucket Cloud servers: Check your…
AI-assisted analysis of SonarSource/sonarqube@184c821202 (2026-09-09).
Data as JSON: /api/errors/311e3afc0365fb08.
Report an issue: GitHub.
Appendix: source
Thrown at server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/onboarding/alm/OnboardingAlmConfiguration.java:316
try {
AlmSettingDto almSettingDto;
try (DbSession dbSession = dbClient.openSession(false)) {
almSettingDto = dbClient.almSettingDao().selectByKey(dbSession, setting.key()).orElse(null);
}
if (almSettingDto == null) {
return OptionalLong.empty();
}
String clientId = almSettingDto.getClientId();
String clientSecret = decryptor.decrypt(almSettingDto.getClientSecret());
if (clientId == null || clientSecret == null) {
return OptionalLong.empty();
}
String accessToken = client.createAccessToken(clientId, clientSecret);
var repoList = client.searchReposWithAccessToken(accessToken, workspace, null, 1, 1);
Integer size = repoList != null ? repoList.getSize() : null;
return size != null ? OptionalLong.of(size) : OptionalLong.empty();
} catch (Exception e) {
LOG.warn("Failed to count bitbucket_cloud repos for ALM setting '{}'", setting.key(), e);
return OptionalLong.empty();
}
}
}
}
View on GitHub (pinned to 184c821202)