apache/druid · error · IllegalArgumentException

connectURI cannot be null or empty

Error message

connectURI cannot be null or empty

What it means

SQLInputSourceDatabaseConnector.validateConfigs() validates JDBC connectivity for the SQL input source. It throws IllegalArgumentException when the connectURI string is null or empty, because a JDBC connection cannot be established without a URL. The check precedes the allowed-properties security validation.

Source

Thrown at server/src/main/java/org/apache/druid/metadata/SQLInputSourceDatabaseConnector.java:92

    // We validate only the connection URL here as all properties will be read from only the URL except
    // users and password. If we want to allow another way to specify user properties such as using
    // MetadataStorageConnectorConfig.getDbcpProperties(), those properties should be validated as well.
    validateConfigs(connectorConfig.getConnectURI(), securityConfig);
    BasicDataSource dataSource = new BasicDataSourceExt(connectorConfig);
    dataSource.setUsername(connectorConfig.getUser());
    dataSource.setPassword(connectorConfig.getPassword());
    String uri = connectorConfig.getConnectURI();
    dataSource.setUrl(uri);
    dataSource.setTestOnBorrow(true);
    dataSource.setValidationQuery(getValidationQuery());

    return dataSource;
  }

  private void validateConfigs(String urlString, JdbcAccessSecurityConfig securityConfig)
  {
    if (Strings.isNullOrEmpty(urlString)) {
      throw new IllegalArgumentException("connectURI cannot be null or empty");
    }
    if (!securityConfig.isEnforceAllowedProperties()) {
      // You don't want to do anything with properties.
      return;
    }
    final Set<String> propertyKeyFromConnectURL = findPropertyKeysFromConnectURL(urlString, securityConfig.isAllowUnknownJdbcUrlFormat());
    ConnectionUriUtils.throwIfPropertiesAreNotAllowed(
        propertyKeyFromConnectURL,
        securityConfig.getSystemPropertyPrefixes(),
        securityConfig.getAllowedProperties()
    );
  }

  public String getValidationQuery()
  {
    return "SELECT 1";
  }

View on GitHub (pinned to 9b90983fd2)

Solutions

  1. Set a valid JDBC connectURI in the SQL input source spec (e.g. jdbc:mysql://host:3306/db or jdbc:postgresql://host:5432/db).
  2. Check that environment-variable or template substitution actually populated the URL.
  3. Validate the spec with the ingestion-spec validator before submitting.

Example fix

// before
"sqlInputSource": { "connectURI": "", "user": "u", "password": "p" }
// after
"sqlInputSource": { "connectURI": "jdbc:postgresql://dbhost:5432/druid", "user": "u", "password": "p" }
Defensive patterns

Strategy: validation

Validate before calling

if (connectURI == null || connectURI.trim().isEmpty()) {
  throw new IllegalArgumentException("sqlInputSource.connectURI is required");
}
if (!connectURI.startsWith("jdbc:")) {
  throw new IllegalArgumentException("connectURI must be a jdbc: URL");
}

Type guard

boolean hasConnectUri(Map<String, Object> spec) {
  Object uri = spec.get("connectURI");
  return uri instanceof String && !((String) uri).isEmpty();
}

Try / catch

try {
  connector.getDatasource(...);
} catch (IllegalArgumentException e) {
  log.error(e, "Invalid SQL input source config: %s", e.getMessage());
}

Prevention

When it happens

Trigger: Submitting an SQL input-source spec whose connectURI field is missing or empty string; programmatic use of getDatasource() with a null url.

Common situations: Hand-written ingestion specs omitting 'connectURI'; templating/variable substitution leaving the URL blank; connector config where the JDBC URL was moved to a different field name.

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 apache/druid@9b90983fd2 (2026-09-07). Data as JSON: /api/errors/57cba2419ad7f9ca. Report an issue: GitHub.