{"record":{"id":"23c27a4648705a7e","repo":"apache/beam","slug":"invalid-url-s","errorCode":null,"errorMessage":"Invalid URL: %s","messagePattern":"Invalid URL: (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"sdks/java/extensions/google-cloud-platform-core/src/main/java/org/apache/beam/sdk/extensions/gcp/util/Transport.java","lineNumber":94,"sourceCode":"    public String servicePath;\n\n    public ApiComponents(String root, String path) {\n      this.rootUrl = root;\n      this.servicePath = path;\n    }\n  }\n\n  private static ApiComponents apiComponentsFromUrl(String urlString) {\n    try {\n      URL url = new URL(urlString);\n      String rootUrl =\n          url.getProtocol()\n              + \"://\"\n              + url.getHost()\n              + (url.getPort() > 0 ? \":\" + url.getPort() : \"\");\n      return new ApiComponents(rootUrl, url.getPath());\n    } catch (MalformedURLException e) {\n      throw new RuntimeException(\"Invalid URL: \" + urlString);\n    }\n  }\n\n  /** Returns a Cloud Storage client builder using the specified {@link GcsOptions}. */\n  public static Storage.Builder newStorageClient(GcsOptions options) {\n    String applicationName =\n        String.format(\n            \"%sapache-beam/%s (GPN:Beam)\",\n            isNullOrEmpty(options.getAppName()) ? \"\" : options.getAppName() + \" \",\n            ReleaseInfo.getReleaseInfo().getSdkVersion());\n\n    String servicePath = options.getGcsEndpoint();\n\n    Storage.Builder storageBuilder =\n        new Storage.Builder(\n                getTransport(), getJsonFactory(), httpRequestInitializerFromOptions(options))\n            .setApplicationName(applicationName)\n            .setGoogleClientRequestInitializer(options.getGoogleApiTrace());","sourceCodeStart":76,"sourceCodeEnd":112,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/extensions/google-cloud-platform-core/src/main/java/org/apache/beam/sdk/extensions/gcp/util/Transport.java#L76-L112","documentation":"Transport.apiComponentsFromUrl parses an API root URL string into ApiComponents (rootUrl + path). If the string is not a valid URL per java.net.URL, the caught MalformedURLException is rethrown as a RuntimeException with the offending string.","triggerScenarios":"Passing a malformed urlString to apiComponentsFromUrl, e.g. a URL missing a protocol ('myhost/api') or containing illegal characters, typically via a misconfigured API root URL option.","commonSituations":"Users set a custom GCS/API endpoint (e.g. emulator or VPC endpoint) without the 'https://' scheme, or with a typo/whitespace in the endpoint string.","solutions":["Ensure the endpoint string includes a valid protocol, e.g. 'https://storage.googleapis.com/'","Trim whitespace and remove quotes/typos from the configured URL","If set programmatically, validate with new URI(urlString) before passing it in"],"exampleFix":"// before\noptions.setGcsEndpoint(\"storage.googleapis.com\");\n// after\noptions.setGcsEndpoint(\"https://storage.googleapis.com\");","handlingStrategy":"validation","validationCode":"try { new java.net.URI(urlString); new java.net.URL(urlString); } catch (Exception e) { throw new IllegalArgumentException(\"Bad endpoint URL: \" + urlString, e); }","typeGuard":"boolean isValidUrl(String s) { try { new java.net.URL(s); return true; } catch (java.net.MalformedURLException e) { return false; } }","tryCatchPattern":"try { components(urlString); } catch (RuntimeException e) { if (e.getMessage().startsWith(\"Invalid URL:\")) { /* fix config and retry with validated URL */ } else throw e; }","preventionTips":["Always include scheme (https://) in custom endpoints","Validate endpoint strings at config-load time","Trim and quote-check values from environment/YAML config"],"tags":["url","java","configuration"],"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"}