{"record":{"id":"8c05c9a0758c0069","repo":"apache/hadoop","slug":"invalid-bucket-name-s-or-object-name-s","errorCode":null,"errorMessage":"Invalid bucket name (%s) or object name (%s)","messagePattern":"Invalid bucket name \\((.+?)\\) or object name \\((.+?)\\)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hadoop-cloud-storage-project/hadoop-gcp/src/main/java/org/apache/hadoop/fs/gs/UriPaths.java","lineNumber":109,"sourceCode":"\n  /**\n   * Constructs and returns full path for the given bucket and object names.\n   */\n  public static URI fromStringPathComponents(String bucketName, String objectName,\n      boolean allowEmptyObjectName) {\n    if (allowEmptyObjectName && bucketName == null && objectName == null) {\n      return GoogleCloudStorageFileSystem.GCSROOT;\n    }\n\n    String authority = StringPaths.validateBucketName(bucketName);\n    String path = PATH_DELIMITER + StringPaths.validateObjectName(objectName, allowEmptyObjectName);\n\n    try {\n      return new URI(SCHEME, authority, path,\n          /* query= */ null,\n          /* fragment= */ null);\n    } catch (URISyntaxException e) {\n      throw new IllegalArgumentException(\n          String.format(\"Invalid bucket name (%s) or object name (%s)\", bucketName, objectName), e);\n    }\n  }\n}\n","sourceCodeStart":91,"sourceCodeEnd":114,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-cloud-storage-project/hadoop-gcp/src/main/java/org/apache/hadoop/fs/gs/UriPaths.java#L91-L114","documentation":"UriPaths (hadoop-gcp) rebuilds a gs:// URI via new URI(\"gs\", authority, path, null, null) after validateBucketName/validateObjectName succeed. If the bucket or object name contains characters java.net.URI does not accept in the authority/path components (spaces, '{', '|', non-ASCII, '%', etc.), URISyntaxException is raised and rethrown as IllegalArgumentException('Invalid bucket name (%s) or object name (%s)') with the original cause attached. The message shows the offending raw values, so inspect them for illegal characters.","triggerScenarios":"Calling UriPaths.toUri (directly or via GoogleCloudStorageFileSystem/GHFS APIs that reconstruct URIs from decoded bucket+object pairs) with a bucket name containing spaces or uppercase/underscore-incompatible characters, or an object name containing characters like ' ', '{', '}', '|', '\\\\', '^', '\"', '<', '>', '`' or raw '%' that break URI syntax.","commonSituations":"Porting keys from S3/HDFS that contain spaces or Unicode; user-supplied filenames pasted into paths; percent-encoding lost after string round-trips; log scrubbing that injects template characters into keys.","solutions":["Percent-encode the object name per RFC 3986 before constructing the URI (encode each path segment, keep '/' separators).","Sanitize file names at ingest: replace spaces and non-URI-safe characters with '-' or '_'.","Verify the bucket name passes GCS naming rules (lowercase, digits, dash, dot, 3-222 chars) — validateBucketName runs first, so failures here are usually the object name.","Keep the original URISyntaxException (attached cause) when reporting; it names the exact index of the bad character."],"exampleFix":"// before\nString objectName = \"my file.txt\"; // space breaks new URI(...)\nURI u = UriPaths.toUri(bucket, objectName, false);\n\n// after\nString encoded = Arrays.stream(objectName.split(\"/\", -1))\n    .map(s -> URLEncoder.encode(s, StandardCharsets.UTF_8).replace(\"+\", \"%20\"))\n    .collect(Collectors.joining(\"/\"));\nURI u = UriPaths.toUri(bucket, encoded, false);","handlingStrategy":"validation","validationCode":"static boolean isUriSafe(String s) {\n  return s != null && new org.apache.hadoop.fs.Path(s).toUri().isAbsolute()\n      ? true : false;\n}\n// stricter: try the exact construction UriPaths uses\nstatic boolean uriConstructs(String bucket, String object) {\n  try {\n    new java.net.URI(\"gs\", bucket, \"/\" + object, null, null);\n    return true;\n  } catch (URISyntaxException e) { return false; }\n}","typeGuard":"static String encodeSegment(String s) {\n  try {\n    return java.net.URLEncoder.encode(s, \"UTF-8\").replace(\"+\", \"%20\");\n  } catch (UnsupportedEncodingException e) { throw new AssertionError(e); }\n}\n// guard: return encoded copy only when raw differs\nstatic String safeSegment(String s) { return s.matches(\"[A-Za-z0-9._~-]+\") ? s : encodeSegment(s); }","tryCatchPattern":"try {\n  return UriPaths.toUri(bucket, object, allowEmpty);\n} catch (IllegalArgumentException e) {\n  if (e.getCause() instanceof URISyntaxException) {\n    throw new UserInputException(\"Key contains URI-unsafe characters: \"\n        + bucket + \"/\" + object, e);\n  }\n  throw e;\n}","preventionTips":["Encode each path segment at ingest; keep '/' as the only raw separator.","Sanitize filenames early: s.replaceAll(\"[^A-Za-z0-9._/-]\", \"_\").","Log the URISyntaxException index — it pinpoints the offending character."],"tags":["hadoop-gcp","gcs","uri-syntax","illegal-argument","encoding"],"backgroundTag":"invalid-bucket-name","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}