{"record":{"id":"3db46a7a158f1248","repo":"apache/beam","slug":"could-not-parse-pubsub-root-url-s","errorCode":null,"errorMessage":"Could not parse pubsub root url \"%s\"","messagePattern":"Could not parse pubsub root url \"(.+?)\"","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/pubsub/PubsubOptions.java","lineNumber":48,"sourceCode":"\n/** Properties that can be set when using Google Cloud Pub/Sub with the Apache Beam SDK. */\n@Description(\n    \"Options that are used to configure Google Cloud Pub/Sub. See \"\n        + \"https://cloud.google.com/pubsub/docs/overview for details on Cloud Pub/Sub.\")\npublic interface PubsubOptions\n    extends ApplicationNameOptions, GcpOptions, PipelineOptions, StreamingOptions {\n\n  /**\n   * Internal only utility for converting {@link #getPubsubRootUrl()} (e.g. {@code https://<host>})\n   * to an endpoint target, usable by GCP client libraries (e.g. {@code <host>:443})\n   */\n  @Internal\n  static String targetForRootUrl(String urlString) {\n    URL url;\n    try {\n      url = new URL(urlString);\n    } catch (MalformedURLException e) {\n      throw new IllegalArgumentException(\n          String.format(\"Could not parse pubsub root url \\\"%s\\\"\", urlString), e);\n    }\n\n    int port = url.getPort();\n\n    if (port < 0) {\n      switch (url.getProtocol()) {\n        case \"https\":\n          port = 443;\n          break;\n        case \"http\":\n          port = 80;\n          break;\n        default:\n          throw new IllegalArgumentException(\n              String.format(\n                  \"Could not determine port for pubsub root url \\\"%s\\\". You must either specify the port or use the protocol \\\"https\\\" or \\\"http\\\"\",\n                  urlString));","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/pubsub/PubsubOptions.java#L30-L66","documentation":"PubsubOptions.targetForRootUrl converts a custom Pub/Sub root URL into a host[:port] target for the gRPC channel. If the URL string cannot be parsed by java.net.URL (MalformedURLException), it throws IllegalArgumentException with this message and the cause.","triggerScenarios":"Setting the pubsubRootUrl option/property to a malformed string, e.g. missing scheme ('localhost:8085' is fine, but 'localhost//' or '::bad::' is not) or containing invalid characters.","commonSituations":"Pointing at a local emulator or mock server and typos in the URL, quoting mistakes in config files, or missing the scheme entirely in ways java.net.URL rejects.","solutions":["Fix the pubsubRootUrl value to be a well-formed absolute URL, e.g. 'https://pubsub.googleapis.com' or 'http://localhost:8085'.","Validate the URL with new URL(...) or a regex before setting the option.","Check the config file/flag for stray characters, spaces, or unescaped quotes."],"exampleFix":"// before\n--pubsubRootUrl=localhost:8085   // may be rejected depending on parse\n// after\n--pubsubRootUrl=http://localhost:8085","handlingStrategy":"validation","validationCode":"try { new java.net.URL(urlString); } catch (java.net.MalformedURLException e) {\n  throw new IllegalArgumentException(\"pubsubRootUrl must be an absolute URL like http://localhost:8085\", e);\n}","typeGuard":null,"tryCatchPattern":"try {\n  options.setPubsubRootUrl(urlString);\n} catch (IllegalArgumentException e) {\n  log.error(\"Bad pubsubRootUrl: {}\", urlString, e);\n}","preventionTips":["Always include a scheme (http:// or https://) in pubsubRootUrl","Validate URLs in config before launching pipelines","For the emulator use http://localhost:8085"],"tags":["java","pubsub","url","configuration","illegal-argument"],"backgroundTag":"invalid-url-format","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}