{"record":{"id":"b65250fe82c98c37","repo":"apache/beam","slug":"could-not-determine-port-for-pubsub-root-url-s-you-must","errorCode":null,"errorMessage":"Could not determine port for pubsub root url \"%s\". You must either specify the port or use the protocol \"https\" or \"http\"","messagePattern":"Could not determine port for pubsub root url \"(.+?)\"\\. You must either specify the port or use the protocol \"https\" or \"http\"","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":63,"sourceCode":"    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));\n      }\n    }\n\n    return String.format(\"%s:%d\", url.getHost(), port);\n  }\n\n  /** Root URL for use with the Google Cloud Pub/Sub API. */\n  @Description(\"Root URL for use with the Google Cloud Pub/Sub API\")\n  @Default.String(\"https://pubsub.googleapis.com\")\n  @Hidden\n  String getPubsubRootUrl();\n\n  void setPubsubRootUrl(String value);\n}\n","sourceCodeStart":45,"sourceCodeEnd":81,"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#L45-L81","documentation":"PubsubOptions.targetForRootUrl needs a port to build the gRPC target. If the URL has no explicit port and the protocol is neither https (443) nor http (80), it cannot infer a port and throws IllegalArgumentException telling the user to specify a port or use http/https.","triggerScenarios":"Setting pubsubRootUrl to something like 'ftp://host' or 'https://host:0/unknown-scheme://host' — i.e. a scheme other than http/https and no port in the URL.","commonSituations":"Configuring a custom Pub/Sub endpoint with an exotic scheme, or forgetting the port when pointing at a local emulator with a non-http scheme.","solutions":["Include an explicit port in the URL, e.g. 'grpc://localhost:8085' or 'myproto://host:8443'.","Use http:// or https:// as the scheme so the default ports (80/443) apply.","For the emulator use the standard 'http://localhost:8085'."],"exampleFix":"// before\n--pubsubRootUrl=grpc://localhost   // no port, unknown scheme\n// after\n--pubsubRootUrl=grpc://localhost:8085","handlingStrategy":"validation","validationCode":"java.net.URL u = new java.net.URL(urlString);\nif (u.getPort() < 0 && !u.getProtocol().equals(\"https\") && !u.getProtocol().equals(\"http\")) {\n  throw new IllegalArgumentException(\"pubsubRootUrl needs an explicit port or http/https scheme\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  options.setPubsubRootUrl(urlString);\n} catch (IllegalArgumentException e) {\n  // append a port or switch scheme to http/https and retry\n}","preventionTips":["Always specify the port for custom endpoints","Use http/https schemes to inherit default ports","Standardize on http://localhost:8085 for the emulator"],"tags":["java","pubsub","url","configuration","port"],"backgroundTag":"invalid-config-value","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"}