{"record":{"id":"630ee92b3c05a589","repo":"apache/beam","slug":"unable-to-create-uri-for-gcs-path-s","errorCode":null,"errorMessage":"Unable to create URI for GCS path %s","messagePattern":"Unable to create URI for GCS path (.+?)","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/gcsfs/GcsPath.java","lineNumber":600,"sourceCode":"  }\n\n  // TODO: Consider using resource names for all GCS paths used by the SDK.\n  public String toResourceName() {\n    StringBuilder sb = new StringBuilder();\n    sb.append(\"storage.googleapis.com/\");\n    if (!bucket.isEmpty()) {\n      sb.append(bucket).append('/');\n    }\n    sb.append(object);\n    return sb.toString();\n  }\n\n  @Override\n  public URI toUri() {\n    try {\n      return new URI(SCHEME, \"//\" + bucketAndObject(), null);\n    } catch (URISyntaxException e) {\n      throw new RuntimeException(\"Unable to create URI for GCS path \" + this);\n    }\n  }\n\n  private String bucketAndObject() {\n    if (bucket.isEmpty()) {\n      return object;\n    } else {\n      return bucket + \"/\" + object;\n    }\n  }\n\n  /** Returns the prefix portion of the glob before the first wildcard character. */\n  public static String getNonWildcardPrefix(String globExp) {\n    Matcher m = GLOB_PREFIX.matcher(globExp);\n    checkArgument(m.matches(), String.format(\"Glob expression: [%s] is not expandable.\", globExp));\n    return m.group(\"PREFIX\");\n  }\n","sourceCodeStart":582,"sourceCodeEnd":618,"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/gcsfs/GcsPath.java#L582-L618","documentation":"GcsPath.toUri() builds a hierarchical URI of the form gs://bucket/object via new URI(SCHEME, \"//\" + bucketAndObject(), null). If the bucket/object contains characters that are illegal in a URI (e.g. spaces, unencoded special characters), URISyntaxException is caught and rethrown as a RuntimeException.","triggerScenarios":"Calling toUri() on a GcsPath whose bucket or object name contains characters invalid for URIs, such as raw spaces, '#', or other reserved characters that the multi-argument URI constructor rejects in that component.","commonSituations":"Objects uploaded by other tools with unencoded filenames (spaces, unicode punctuation) then processed through Beam's GCS filesystem; constructing URIs for logging or comparison.","solutions":["Rename/sanitize the GCS object to contain URI-safe characters","Percent-encode the object name before creating the GcsPath (e.g. URLEncoder on path segments)","Catch the RuntimeException at the call site and skip/handle such objects"],"exampleFix":"// before\nURI uri = new URI(\"gs\", \"//\" + bucket + \"/\" + object, null);\n// after\nString enc = java.net.URLEncoder.encode(object, StandardCharsets.UTF_8)\n    .replace(\"+\", \"%20\");\nURI uri = new URI(\"gs\", \"//\" + bucket + \"/\" + enc, null);","handlingStrategy":"try-catch","validationCode":"new java.net.URI(\"gs\", \"//\" + path.getBucket() + \"/\" + path.getObject(), null); // pre-validate","typeGuard":null,"tryCatchPattern":"try { URI uri = path.toUri(); } catch (RuntimeException e) { if (e.getMessage().startsWith(\"Unable to create URI\")) { /* sanitize object name or skip */ } else throw e; }","preventionTips":["Sanitize GCS object names to URI-safe characters before processing","Percent-encode path segments from external uploads","Skip or quarantine objects with reserved characters like spaces and '#'"],"tags":["gcs","java","uri","encoding"],"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-20T03:17:13.778Z"}