{"record":{"id":"52e49af47d11da38","repo":"apache/beam","slug":"host-cannot-be-empty-in-jdbc-url","errorCode":null,"errorMessage":"Host cannot be empty in JDBC URL: ","messagePattern":"Host cannot be empty in JDBC URL: ","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"sdks/java/io/clickhouse/src/main/java/org/apache/beam/sdk/io/clickhouse/ClickHouseJdbcUrlParser.java","lineNumber":208,"sourceCode":"   */\n  private static void validateScheme(String scheme) {\n    if (scheme == null || (!scheme.equals(\"http\") && !scheme.equals(\"https\"))) {\n      throw new IllegalArgumentException(\n          \"Invalid scheme. Expected 'http' or 'https'. Got: \" + scheme);\n    }\n  }\n\n  /**\n   * Validates and returns the host from the URI.\n   *\n   * @param host the host to validate\n   * @param jdbcUrl the original JDBC URL (for error reporting)\n   * @return the validated host\n   * @throws IllegalArgumentException if host is invalid\n   */\n  private static String validateAndGetHost(String host, String jdbcUrl) {\n    if (Strings.isNullOrEmpty(host)) {\n      throw new IllegalArgumentException(\"Host cannot be empty in JDBC URL: \" + jdbcUrl);\n    }\n    return host;\n  }\n\n  /**\n   * Returns the port or default port based on scheme.\n   *\n   * @param port the port from URI (-1 if not specified)\n   * @param scheme the URI scheme (http or https)\n   * @return the port number\n   */\n  private static int getPortOrDefault(int port, String scheme) {\n    if (port == -1) {\n      return scheme.equals(\"https\") ? 8443 : 8123; // Default ClickHouse ports\n    }\n    return port;\n  }\n","sourceCodeStart":190,"sourceCodeEnd":226,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/io/clickhouse/src/main/java/org/apache/beam/sdk/io/clickhouse/ClickHouseJdbcUrlParser.java#L190-L226","documentation":"Thrown by ClickHouseJdbcUrlParser.validateAndGetHost when the host extracted from the JDBC URI is null or empty (checked via Guava Strings.isNullOrEmpty). A ClickHouse JDBC connection must point at a concrete server host.","triggerScenarios":"Parsing URLs with an empty authority, e.g. 'jdbc:clickhouse:http:///default' or 'jdbc:ch://', where nothing appears between '//' and the next '/'.","commonSituations":"Config where the HOST env var/property is empty so the template renders 'jdbc:ch://:8123'; templating engines silently dropping an unset variable; copy-paste losing the host part.","solutions":["Add the hostname or IP between '//' and the next '/' in the JDBC URL.","Check that the host config variable is set and non-empty before building the URL.","Inspect the jdbcUrl in the message to see where the authority went missing.","Use 'localhost' explicitly for local development rather than omitting the host."],"exampleFix":"// before\nString url = \"jdbc:clickhouse:http:///default\"; // empty host\n// after\nString url = \"jdbc:clickhouse:http://localhost:8123/default\";","handlingStrategy":"validation","validationCode":"boolean hasHost(String jdbcUrl) {\n  if (jdbcUrl == null) return false;\n  try {\n    String host = new java.net.URI(jdbcUrl.substring(jdbcUrl.indexOf(':') + 1)).getHost();\n    return host != null && !host.isBlank();\n  } catch (Exception e) { return false; }\n}","typeGuard":null,"tryCatchPattern":"try {\n  ParsedJdbcUrl parsed = ClickHouseJdbcUrlParser.parse(jdbcUrl);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage() != null && e.getMessage().contains(\"Host cannot be empty\")) {\n    throw new ConfigException(\"ClickHouse host is missing — check host config variable\", e);\n  }\n  throw e;\n}","preventionTips":["Fail fast on empty host config values before building the URL.","Always include an explicit host, even 'localhost'; don't rely on defaults.","Check templating output for silently dropped variables (e.g. ${HOST} unset).","Add an integration smoke test that parses the final URL in CI."],"tags":["jdbc","clickhouse","url-parsing","configuration"],"backgroundTag":"empty-required-field","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}