SonarSource/sonarqube · error · IllegalArgumentException

Invalid URL, %s

Error message

Invalid URL, %s

What it means

In checkApiEndpoint, after the blank check, the endpoint string is parsed with URI.create; if that throws IllegalArgumentException (invalid URI syntax), it is rethrown as "Invalid URL, <reason>". It means the configured GitHub API endpoint is not a syntactically valid URI (e.g. contains spaces or illegal characters) rather than the endpoint being unreachable.

Source

Thrown at server/sonar-alm-client/src/main/java/org/sonar/alm/client/github/GithubApplicationClientImpl.java:160

      ApplicationHttpClient.Response response = githubApplicationHttpClient.post(baseUrl, token, endPoint, extraHeaders);
      return handleResponse(response, endPoint, gsonClass);
    } catch (Exception e) {
      LOG.warn(FAILED_TO_REQUEST_BEGIN_MSG + endPoint, e);
      return Optional.empty();
    }
  }

  @Override
  public void checkApiEndpoint(GithubAppConfiguration githubAppConfiguration) {
    if (StringUtils.isBlank(githubAppConfiguration.getApiEndpoint())) {
      throw new IllegalArgumentException("Missing URL");
    }

    URI apiEndpoint;
    try {
      apiEndpoint = URI.create(githubAppConfiguration.getApiEndpoint());
    } catch (IllegalArgumentException e) {
      throw new IllegalArgumentException("Invalid URL, " + e.getMessage());
    }

    if (!"http".equalsIgnoreCase(apiEndpoint.getScheme()) && !"https".equalsIgnoreCase(apiEndpoint.getScheme())) {
      throw new IllegalArgumentException("Only http and https schemes are supported");
    } else if (!isValidGitHubUrl(apiEndpoint)) {
      throw new IllegalArgumentException("Invalid GitHub URL");
    }
  }

  private static boolean isValidGitHubUrl(URI apiEndpoint) {
    String host = apiEndpoint.getHost();
    String path = apiEndpoint.getPath();
    if (host == null) {
      return false;
    }

    String lowerCaseHost = host.toLowerCase(Locale.ENGLISH);
    // GitHub.com (official public GitHub)

View on GitHub (pinned to 184c821202)

Solutions

  1. Inspect the configured API URL for stray whitespace, newlines, or unescaped special characters and fix it
  2. Ensure the URL includes the scheme (https://) and is properly percent-encoded
  3. Use the plain base API URL (e.g. https://api.github.com or https://<host>/api/v3) without placeholders
  4. Trim the value programmatically before constructing GithubAppConfiguration

Example fix

// before
String apiEndpoint = properties.getProperty("github.url"); // " https://github.example.com/api/v3 " (leading/trailing spaces)
// after
String apiEndpoint = properties.getProperty("github.url").trim(); // "https://github.example.com/api/v3"
Defensive patterns

Strategy: validation

Validate before calling

// Java: validate URI syntax before calling checkApiEndpoint
try {
  URI uri = new URI(apiEndpoint.trim());
  if (uri.getScheme() == null || uri.getHost() == null) {
    throw new IllegalArgumentException("GitHub API endpoint must be an absolute http(s) URL");
  }
} catch (URISyntaxException e) {
  throw new IllegalArgumentException("GitHub API endpoint is not a valid URL: " + e.getMessage());
}

Type guard

// Java: safe parse of the endpoint string
static Optional<URI> parseApiEndpoint(String raw) {
  try {
    return Optional.of(URI.create(raw == null ? "" : raw.trim()));
  } catch (IllegalArgumentException e) {
    return Optional.empty();
  }
}

Try / catch

try {
  githubApplicationClient.checkApiEndpoint(githubAppConfiguration);
} catch (IllegalArgumentException e) {
  if (e.getMessage() != null && e.getMessage().startsWith("Invalid URL, ")) {
    throw new ConfigurationException("Fix the GitHub API URL syntax (no spaces/unescaped characters, include https://): " + e.getMessage());
  }
  throw e;
}

Prevention

When it happens

Trigger: checkApiEndpoint invoked with an apiEndpoint string that URI.create cannot parse — spaces, unescaped special characters, missing scheme characters, control characters.

Common situations: Pasting a URL with a trailing space or newline from a config file; unescaped characters such as '|', '<', or a space inside the path; using a placeholder like '<your-github-url>' that was never substituted; URL copied with hidden non-ASCII characters.

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/264658ce425ef93b. Report an issue: GitHub.