SonarSource/sonarqube · error · IllegalArgumentException

%s

Error message

%s

What it means

Thrown by WebhookSupport.checkUrlPattern when the webhook URL cannot be parsed by OkHttp's HttpUrl, causing the caller-supplied message (with its format arguments) to be wrapped in an IllegalArgumentException. This is the generic 'your webhook URL string is malformed' failure raised by api/webhooks/create and api/webhooks/update.

Solutions

  1. Ensure the URL is a valid absolute http(s) URL including scheme, e.g. https://hooks.example.com/sonarqube.
  2. Echo/inspect the value actually passed (env vars, CI secrets) to catch empty or unsubstituted placeholders.
  3. Trim whitespace and re-run the request.

Example fix

// before
curl -u $TOKEN -X POST "$SONAR/api/webhooks/create?name=ci&url=$WEBHOOK_URL" // WEBHOOK_URL empty -> parse fails
// after
: "${WEBHOOK_URL:?must be a valid https URL}"
curl -u $TOKEN -X POST "$SONAR/api/webhooks/create?name=ci&url=$WEBHOOK_URL"
Defensive patterns

Strategy: validation

Validate before calling

boolean isValidWebhookUrl(String url) {
  try {
    java.net.URI u = java.net.URI.create(url.trim());
    return (u.getScheme().equals("http") || u.getScheme().equals("https")) && u.getHost() != null;
  } catch (Exception | NullPointerException e) {
    return false;
  }
}

Type guard

boolean isNonEmptyHttpUrl(Object v) {
  return v instanceof String s && !s.isBlank() && (s.startsWith("http://") || s.startsWith("https://"));
}

Try / catch

try {
  createWebhook(name, url);
} catch (IllegalArgumentException e) {
  throw new ConfigurationException("Webhook URL is not a valid absolute http(s) URL: " + url, e);
}

Prevention

When it happens

Trigger: POST api/webhooks/create or update with a 'url' parameter that is not a valid absolute HTTP(S) URL, e.g. missing scheme, containing spaces or invalid characters, or being an empty/garbage string; the format message then describes the invalid URL.

Common situations: Environment variable holding the URL left empty or containing trailing whitespace/newline; URL quoted incorrectly in shell scripts; forgetting 'https://'; template placeholders like ${WEBHOOK_URL} not substituted by the templating engine.

Understand the failure class

Background: "Invalid URL" / "URL cannot be empty": fix the malformed or missing URL behind request-construction failures — this error's family across 50 libraries.

Related errors


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

Appendix: source

Thrown at server/sonar-webserver-webapi/src/main/java/org/sonar/server/webhook/ws/WebhookSupport.java:61

  public WebhookSupport(UserSession userSession, Configuration configuration, NetworkInterfaceProvider networkInterfaceProvider) {
    this.userSession = userSession;
    this.configuration = configuration;
    this.networkInterfaceProvider = networkInterfaceProvider;
  }

  void checkPermission(ProjectDto projectDto) {
    userSession.checkEntityPermission(ProjectPermission.ADMIN, projectDto);
  }

  void checkPermission() {
    userSession.checkPermission(GlobalPermission.ADMINISTER);
  }

  void checkUrlPattern(String url, String message, Object... messageArguments) {
    try {
      HttpUrl okUrl = HttpUrl.parse(url);
      if (okUrl == null) {
        throw new IllegalArgumentException(String.format(message, messageArguments));
      }
      InetAddress address = InetAddress.getByName(okUrl.host());

      if (configuration.getBoolean(SONAR_VALIDATE_WEBHOOKS_PROPERTY)
        .orElse(SONAR_VALIDATE_WEBHOOKS_DEFAULT_VALUE)
        && WebhookAddressValidator.isBlockedAddress(address, networkInterfaceProvider)) {
        throw new IllegalArgumentException(WebhookAddressValidator.INVALID_ADDRESS_MESSAGE);
      }
    } catch (UnknownHostException e) {
      // if a host can not be resolved the deliveries will fail - no need to block it from being set
      // this will only happen for public URLs
    } catch (SocketException e) {
      throw new IllegalStateException("Can not retrieve a network interfaces", e);
    }
  }
}

View on GitHub (pinned to 184c821202)