{"record":{"id":"756533a334e5bfb0","repo":"apache/hadoop","slug":"gcs-bucket-name-cannot-be-empty","errorCode":null,"errorMessage":"GCS bucket name cannot be empty.","messagePattern":"GCS bucket name cannot be empty\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hadoop-cloud-storage-project/hadoop-gcp/src/main/java/org/apache/hadoop/fs/gs/StringPaths.java","lineNumber":58,"sourceCode":"      .and(CharMatcher.inRange('0', '9').or(CharMatcher.inRange('a', 'z'))\n          .or(CharMatcher.anyOf(\"_.-\")))\n      .precomputed();\n\n  /**\n   * Validate the given bucket name to make sure that it can be used as a part of a file system\n   * path.\n   *\n   * <p>Note: this is not designed to duplicate the exact checks that GCS would perform on the\n   * server side. We make some checks that are relevant to using GCS as a file system.\n   *\n   * @param bucketName Bucket name to check.\n   */\n  static String validateBucketName(String bucketName) {\n    // If the name ends with '/', remove it.\n    bucketName = toFilePath(bucketName);\n\n    if (isNullOrEmpty(bucketName)) {\n      throw new IllegalArgumentException(\"GCS bucket name cannot be empty.\");\n    }\n\n    if (!BUCKET_NAME_CHAR_MATCHER.matchesAllOf(bucketName)) {\n      throw new IllegalArgumentException(String.format(\n          \"Invalid GCS bucket name '%s': bucket name must contain only 'a-z0-9_.-' characters.\",\n          bucketName));\n    }\n\n    return bucketName;\n  }\n\n  /**\n   * Validate the given object name to make sure that it can be used as a part of a file system\n   * path.\n   *\n   * <p>Note: this is not designed to duplicate the exact checks that GCS would perform on the\n   * server side. We make some checks that are relevant to using GCS as a file system.\n   *","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-cloud-storage-project/hadoop-gcp/src/main/java/org/apache/hadoop/fs/gs/StringPaths.java#L40-L76","documentation":"StringPaths.validateBucketName (reached via StorageResourceId.fromUriPath) rejects an empty bucket name: after stripping any trailing '/', the authority must be non-empty. This means the supplied gs URI has no bucket - e.g. 'gs://', 'gs:/path', or 'gs:///key'.","triggerScenarios":"fromUriPath on a URI whose authority is null/empty: 'gs:///object', 'gs://', or a URI built with String.format where the bucket variable was null or empty.","commonSituations":"Building gs:// URIs by string concatenation with an unset bucket config/variable; paths from configs missing the authority; URI parsing that drops the authority component (e.g. resolve() edge cases).","solutions":["Always include the bucket as the URI authority: gs://<bucket>/<object>.","Validate that the bucket variable/config is non-empty before constructing the URI.","Where input is untrusted, fail fast with your own message naming the missing bucket."],"exampleFix":"// before\nURI uri = URI.create(String.format(\"gs://%s/%s\", bucket, object)); // bucket == \"\" -> 'gs:///object'\nStorageResourceId.fromUriPath(uri, false); // IllegalArgumentException\n\n// after\ncheckArgument(!bucket.isEmpty(), \"bucket must be set\");\nURI uri = URI.create(String.format(\"gs://%s/%s\", bucket, object));","handlingStrategy":"validation","validationCode":"String bucket = requiredBucket(); // from config\nif (bucket == null || bucket.isEmpty()) {\n  throw new IllegalArgumentException(\"GCS bucket config is missing\");\n}\nURI uri = URI.create(\"gs://\" + bucket + \"/\" + object);","typeGuard":"static boolean hasGcsBucket(URI u) {\n  String a = u.getAuthority();\n  return a != null && !a.isEmpty();\n}","tryCatchPattern":"catch IllegalArgumentException with message equals(\"GCS bucket name cannot be empty.\") - the URI lacks an authority; rebuild it as gs://<bucket>/<object> before retrying.","preventionTips":["Always format gs URIs as gs://bucket/object with a validated non-empty bucket.","Fail fast on empty bucket config at startup rather than deep in FS calls."],"tags":["uri","gcs","bucket","validation"],"backgroundTag":"invalid-bucket-name","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}