SonarSource/sonarqube · warning
Failed to construct Bitbucket Server repository URL for ALM…
Error message
Failed to construct Bitbucket Server repository URL for ALM setting '{}': invalid server URL What it means
This warning is logged by setBitbucketServerRepositoryUrl when almSetting.getUrl() for a Bitbucket Server integration cannot be parsed into an OkHttp HttpUrl. All three required fields (serverUrl, project key, slug) were non-blank, but the URL itself is invalid, so no repositoryUrl is set on the response.
Solutions
- Update the Bitbucket Server ALM setting so the URL is absolute with a scheme, e.g. https://bitbucket.mycompany.com (api/alm_settings/update_bitbucketserver)
- Re-run GET api/alm_settings/get_binding to confirm the repositoryUrl is now populated
- Validate the URL externally with curl before saving it in SonarQube
- Check the DB ALM_SETTINGS row directly if the UI shows a valid URL but the warning persists (hidden characters)
Example fix
// before: invalid URL alm_settings/update_bitbucketserver?key=bb1&url=bitbucket.mycompany.com // after alm_settings/update_bitbucketserver?key=bb1&url=https://bitbucket.mycompany.com
Defensive patterns
Strategy: validation
Validate before calling
// Validate the Bitbucket Server URL format before saving the setting
java.net.URI u = java.net.URI.create(candidateUrl);
boolean valid = ("https".equals(u.getScheme()) || "http".equals(u.getScheme())) && u.getHost() != null;
if (!valid) throw new IllegalArgumentException("Bitbucket Server URL must be absolute http(s), got: " + candidateUrl); Prevention
- Always include the scheme (https://) in Bitbucket Server URLs
- Trim/normalize input before persisting ALM settings
- Validate settings via api/alm_settings/list right after creation
- Watch for this warning after server migrations that rewrite URLs
When it happens
Trigger: GET api/alm_settings/get_binding for a Bitbucket Server-bound project where the ALM setting's URL is missing a scheme (e.g. 'bitbucket.mycompany.com'), contains invalid characters/spaces, or was truncated during entry or migration.
Common situations: Administrator configured the Bitbucket Server URL without https://; trailing whitespace or hidden characters pasted into the URL field; legacy settings imported from another instance with a malformed URL.
Understand the failure class
Background: "Invalid URL" errors: why new URL(), URI.parse, and reqwest::Url reject your string — missing scheme, whitespace, and bad path format — this error's family across 39 libraries.
Related errors
- Failed to construct GitHub repository URL for ALM setting
- Invalid GitLab project ID
- Missing Client Secret
- a JVM option can't be empty and must start with '-'. The…
- Address contains invalid character: 0x%02x
AI-assisted analysis of SonarSource/sonarqube@184c821202 (2026-09-09).
Data as JSON: /api/errors/d375f9f87b4931ef.
Report an issue: GitHub.
Appendix: source
Thrown at server/sonar-webserver-webapi/src/main/java/org/sonar/server/almsettings/ws/GetBindingAction.java:221
requireNonNull(projectAlmSetting.getAlmRepo()));
builder.setRepositoryUrl(azureRepo.getWebUrl());
}
} catch (Exception e) {
LOG.warn("Failed to fetch Azure repository URL for ALM setting '{}', project '{}' and repository '{}'",
almSetting.getKey(), projectAlmSetting.getAlmSlug(), projectAlmSetting.getAlmRepo(), e);
}
}
}
private static void setBitbucketServerRepositoryUrl(AlmSettingDto almSetting, ProjectAlmSettingDto projectAlmSetting,
GetBindingWsResponse.Builder builder) {
String serverUrl = almSetting.getUrl();
String bitbucketProjectKey = projectAlmSetting.getAlmRepo();
String repositorySlug = projectAlmSetting.getAlmSlug();
if (isNotBlank(serverUrl) && isNotBlank(bitbucketProjectKey) && isNotBlank(repositorySlug)) {
HttpUrl baseUrl = HttpUrl.parse(serverUrl);
if (baseUrl == null) {
LOG.warn("Failed to construct Bitbucket Server repository URL for ALM setting '{}': invalid server URL", almSetting.getKey());
return;
}
builder.setRepositoryUrl(baseUrl.newBuilder()
.addPathSegment("projects")
.addPathSegment(bitbucketProjectKey)
.addPathSegment("repos")
.addPathSegment(repositorySlug)
.build()
.toString());
}
}
}
View on GitHub (pinned to 184c821202)