SonarSource/sonarqube · error · BadRequestException

Invalid URL: ' '.

Error message

Invalid URL: '%s'.

What it means

AlmSettingsSupport.validateUrl rejects null or unparseable DevOps Platform URLs using OkHttp's HttpUrl.parse. It logs a warning and throws BadRequestException (HTTP 400) with the offending URL formatted into the message.

Solutions

  1. Provide an absolute URL including scheme, e.g. https://github.enterprise.example
  2. Trim whitespace and remove surrounding quotes/special characters from the URL
  3. Use http:// only for internal instances where TLS is not available
  4. Validate the URL with a parser (e.g. OkHttp HttpUrl.parse) before submitting

Example fix

// before
almSettings.create("gh", "github.enterprise.example");
// after
almSettings.create("gh", "https://github.enterprise.example");
Defensive patterns

Strategy: validation

Validate before calling

boolean isValidUrl(String u) { return u != null && !u.isBlank() && okhttp3.HttpUrl.parse(u.trim()) != null; }
if (!isValidUrl(url)) throw new IllegalArgumentException("Invalid URL: '" + url + "'.");

Type guard

HttpUrl parsed = url == null ? null : HttpUrl.parse(url);
if (parsed == null) { /* reject before API call */ }

Try / catch

try { support.validateUrl(url); } catch (BadRequestException e) { showUserFriendlyUrlError(); }

Prevention

When it happens

Trigger: Calling alm_settings create/update webservices (or v2 equivalents) with a url that is null, empty, or not a valid absolute HTTP(S) URL, e.g. 'github.com' without scheme or 'htp://typo'.

Common situations: Missing scheme ('mycompany.github.com'); typo'd scheme; trailing content like spaces; copy-paste from docs including markdown; passing empty string from automation.

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


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

Appendix: source

Thrown at server/sonar-webserver-webapi/src/main/java/org/sonar/server/almsettings/ws/AlmSettingsSupport.java:134

    } finally {
      almSettingCreationLock.unlock();
    }
  }

  public void checkBitbucketCloudWorkspaceIDFormat(String workspaceId) {
    if (!WORKSPACE_ID_PATTERN.matcher(workspaceId).matches()) {
      throw BadRequestException.create(String.format(
        "Workspace ID '%s' has an incorrect format. Should only contain lowercase letters, numbers, dashes, and underscores.",
        workspaceId
      ));
    }
  }

  public void validateUrl(@Nullable String url) {
    if (url == null || HttpUrl.parse(url) == null) {
      LOG.warn("Rejected an invalid DevOps Platform URL");
      throw BadRequestException.create(format("Invalid URL: '%s'.", url));
    }
  }

  public void validateAzureName(String fieldName, String value) {
    Matcher matcher = AZURE_NAME_INVALID_CHARS.matcher(value);
    if (matcher.find()) {
      String invalidChar = matcher.group();
      if (LOG.isWarnEnabled()) {
        LOG.warn("Rejected Azure DevOps name for field '{}': contains invalid character '{}'", fieldName, invalidChar);
      }
      throw BadRequestException.create(format(
        "'%s' contains the invalid character '%s'. Azure DevOps names must not contain any of: \\ / : < > | ? *",
        fieldName, invalidChar));
    }
  }

  public ProjectDto getProjectAsAdmin(DbSession dbSession, String projectKey) {
    return getProject(dbSession, projectKey, ADMIN);
  }

View on GitHub (pinned to 184c821202)