{"record":{"id":"d375f9f87b4931ef","repo":"SonarSource/sonarqube","slug":"failed-to-construct-bitbucket-server-repository-ur","errorCode":null,"errorMessage":"Failed to construct Bitbucket Server repository URL for ALM setting '{}': invalid server URL","messagePattern":"Failed to construct Bitbucket Server repository URL for ALM setting '(.+?)': invalid server URL","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"server/sonar-webserver-webapi/src/main/java/org/sonar/server/almsettings/ws/GetBindingAction.java","lineNumber":221,"sourceCode":"            requireNonNull(projectAlmSetting.getAlmRepo()));\n          builder.setRepositoryUrl(azureRepo.getWebUrl());\n        }\n      } catch (Exception e) {\n        LOG.warn(\"Failed to fetch Azure repository URL for ALM setting '{}', project '{}' and repository '{}'\",\n          almSetting.getKey(), projectAlmSetting.getAlmSlug(), projectAlmSetting.getAlmRepo(), e);\n      }\n    }\n  }\n\n  private static void setBitbucketServerRepositoryUrl(AlmSettingDto almSetting, ProjectAlmSettingDto projectAlmSetting,\n    GetBindingWsResponse.Builder builder) {\n    String serverUrl = almSetting.getUrl();\n    String bitbucketProjectKey = projectAlmSetting.getAlmRepo();\n    String repositorySlug = projectAlmSetting.getAlmSlug();\n    if (isNotBlank(serverUrl) && isNotBlank(bitbucketProjectKey) && isNotBlank(repositorySlug)) {\n      HttpUrl baseUrl = HttpUrl.parse(serverUrl);\n      if (baseUrl == null) {\n        LOG.warn(\"Failed to construct Bitbucket Server repository URL for ALM setting '{}': invalid server URL\", almSetting.getKey());\n        return;\n      }\n      builder.setRepositoryUrl(baseUrl.newBuilder()\n        .addPathSegment(\"projects\")\n        .addPathSegment(bitbucketProjectKey)\n        .addPathSegment(\"repos\")\n        .addPathSegment(repositorySlug)\n        .build()\n        .toString());\n    }\n  }\n\n}\n","sourceCodeStart":203,"sourceCodeEnd":235,"githubUrl":"https://github.com/SonarSource/sonarqube/blob/184c821202192afc1c599fc912d0889b69fffa53/server/sonar-webserver-webapi/src/main/java/org/sonar/server/almsettings/ws/GetBindingAction.java#L203-L235","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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)"],"exampleFix":"// before: invalid URL\nalm_settings/update_bitbucketserver?key=bb1&url=bitbucket.mycompany.com\n// after\nalm_settings/update_bitbucketserver?key=bb1&url=https://bitbucket.mycompany.com","handlingStrategy":"validation","validationCode":"// Validate the Bitbucket Server URL format before saving the setting\njava.net.URI u = java.net.URI.create(candidateUrl);\nboolean valid = (\"https\".equals(u.getScheme()) || \"http\".equals(u.getScheme())) && u.getHost() != null;\nif (!valid) throw new IllegalArgumentException(\"Bitbucket Server URL must be absolute http(s), got: \" + candidateUrl);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["alm-integration","bitbucket-server","url-construction","validation"],"backgroundTag":"invalid-url-format","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"}