{"record":{"id":"89af769c3792b6e2","repo":"apache/druid","slug":"invalid-url-format-for-postgresql-s","errorCode":null,"errorMessage":"Invalid URL format for PostgreSQL: [%s]","messagePattern":"Invalid URL format for PostgreSQL: \\[(.+?)\\]","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"processing/src/main/java/org/apache/druid/utils/ConnectionUriUtils.java","lineNumber":193,"sourceCode":"        // no special handling for class not found because postgres driver is in distribution and should be available.\n        throw new RuntimeException(otherPostgres);\n      }\n    } else {\n      if (!allowUnknown) {\n        throw new IAE(\"Unknown JDBC connection scheme: %s\", connectionUri.split(\":\")[1]);\n      }\n      return Collections.emptySet();\n    }\n  }\n\n  public static Set<String> tryParsePostgresConnectionUri(String connectionUri)\n      throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException\n  {\n    Class<?> driverClass = Class.forName(POSTGRES_DRIVER);\n    Method parseUrl = driverClass.getMethod(\"parseURL\", String.class, Properties.class);\n    Properties properties = (Properties) parseUrl.invoke(null, connectionUri, null);\n    if (properties == null) {\n      throw new IAE(\"Invalid URL format for PostgreSQL: [%s]\", connectionUri);\n    }\n    Set<String> keys = Sets.newHashSetWithExpectedSize(properties.size());\n    properties.forEach((k, v) -> keys.add((String) k));\n    return keys;\n  }\n\n  public static Set<String> tryParseMySqlConnectionUri(String connectionUri)\n      throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException,\n             InvocationTargetException\n  {\n    Class<?> connectionUrlClass = Class.forName(MYSQL_CONNECTION_URL);\n    Method isConnectionStringSupported = connectionUrlClass.getMethod(\"acceptsUrl\", String.class);\n    if (!(boolean) isConnectionStringSupported.invoke(connectionUrlClass, connectionUri)) {\n      throw new IAE(\"Invalid URL format for MySQL: [%s]\", connectionUri);\n    }\n    Method getConnectionUrlInstanceMethod = connectionUrlClass.getMethod(\"getConnectionUrlInstance\", String.class, Properties.class);\n    Object conUrl = getConnectionUrlInstanceMethod.invoke(connectionUrlClass, connectionUri, null);\n    Method getHostsList = connectionUrlClass.getMethod(\"getHostsList\");","sourceCodeStart":175,"sourceCodeEnd":211,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/processing/src/main/java/org/apache/druid/utils/ConnectionUriUtils.java#L175-L211","documentation":"tryParsePostgresConnectionUri invokes the pgJDBC driver's internal parseURL method reflectively; it returns null when the connection URI is not a valid PostgreSQL URL. Druid converts that null into this IllegalArgumentException showing the offending URI.","triggerScenarios":"Passing a string the pgJDBC parser rejects: missing jdbc:postgresql: prefix, malformed host/port/components, or a URI for a different database passed into the postgres parsing path.","commonSituations":"Typo'd schemes like jdbc:postgres:... (missing 'ql'), config values copied with extra characters or whitespace, and code paths that route non-postgres URIs into the postgres parser.","solutions":["Correct the URI to the form jdbc:postgresql://host:port/database?params per pgJDBC docs.","Use the correct scheme jdbc:postgresql: (not jdbc:postgres:).","Trim whitespace and stray characters from the configured URI.","Pre-validate the URI with a regex/startsWith check before calling tryParseJdbcUriParameters."],"exampleFix":"// before\nString uri = \"jdbc:postgres://localhost:5432/druid\"; // invalid scheme\nSet<String> keys = tryParsePostgresConnectionUri(uri);\n// after\nString uri = \"jdbc:postgresql://localhost:5432/druid\";\nSet<String> keys = tryParsePostgresConnectionUri(uri);","handlingStrategy":"validation","validationCode":"static boolean looksLikePostgresUri(String uri) {\n  return uri != null && uri.startsWith(\"jdbc:postgresql://\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  params = ConnectionUriUtils.tryParseJdbcUriParameters(uri, false);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage().startsWith(\"Invalid URL format for PostgreSQL\")) {\n    log.error(\"Bad PostgreSQL URI, expected jdbc:postgresql://host:port/db: \" + uri);\n  }\n  throw e;\n}","preventionTips":["Use the exact scheme jdbc:postgresql://host:port/database","Trim whitespace and stray characters from configured URIs","Don't route non-postgres URIs into the postgres parsing path","Test configured JDBC URIs against the pgJDBC parser at config-load time"],"tags":["jdbc","postgresql","url"],"backgroundTag":"invalid-url-format","analyzedSha":"9b90983fd291f26935af934383ce360473179e4d","analyzedAt":"2026-09-07T13:32:30.957Z","contentChangedAt":"2026-09-07T13:32:30.957Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}