{"record":{"id":"b385de7ccbb4d400","repo":"apache/hadoop","slug":"wrong-bucket-s-in-path-s-expected-bucket-s","errorCode":null,"errorMessage":"Wrong bucket: %s, in path: %s, expected bucket: %s","messagePattern":"Wrong bucket: (.+?), in path: (.+?), expected bucket: (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hadoop-cloud-storage-project/hadoop-gcp/src/main/java/org/apache/hadoop/fs/gs/GoogleHadoopFileSystem.java","lineNumber":237,"sourceCode":"    // Validate scheme\n    URI uri = path.toUri();\n\n    String scheme = uri.getScheme();\n    if (scheme != null && !scheme.equalsIgnoreCase(getScheme())) {\n      throw new IllegalArgumentException(\n          String.format(\"Wrong scheme: %s, in path: %s, expected scheme: %s\", scheme, path,\n              getScheme()));\n    }\n\n    String bucket = uri.getAuthority();\n    String rootBucket = fsRoot.toUri().getAuthority();\n\n    // Bucket-less URIs will be qualified later\n    if (bucket == null || bucket.equals(rootBucket)) {\n      return;\n    }\n\n    throw new IllegalArgumentException(\n        String.format(\"Wrong bucket: %s, in path: %s, expected bucket: %s\", bucket, path,\n            rootBucket));\n  }\n\n  /**\n   * Validates that GCS path belongs to this file system. The bucket must match the root bucket\n   * provided at initialization time.\n   */\n  Path getHadoopPath(final URI gcsPath) {\n    LOG.trace(\"getHadoopPath(gcsPath: {})\", gcsPath);\n\n    // Handle root. Delegate to getGcsPath on \"gs:/\" to resolve the appropriate gs://<bucket> URI.\n    if (gcsPath.equals(getGcsPath(fsRoot))) {\n      return fsRoot;\n    }\n\n    StorageResourceId resourceId = StorageResourceId.fromUriPath(gcsPath, true);\n","sourceCodeStart":219,"sourceCodeEnd":255,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-cloud-storage-project/hadoop-gcp/src/main/java/org/apache/hadoop/fs/gs/GoogleHadoopFileSystem.java#L219-L255","documentation":"checkPath also validates the bucket: a Path's authority must be null (bucket-less, qualified later) or equal the root bucket of this FileSystem instance (fsRoot's authority), otherwise IllegalArgumentException 'Wrong bucket'. One GoogleHadoopFileSystem instance serves exactly one GCS bucket.","triggerScenarios":"FileSystem.get(new URI(\"gs://bucket-a\"), conf) then operations on gs://bucket-b/... paths; paths built with a different bucket authority than the instance's root.","commonSituations":"Multi-bucket pipelines (raw/staging/processed buckets) reusing one FileSystem handle; fs.defaultFS bound to one bucket while job configs reference others; templates that swap buckets in path strings but not the FileSystem URI.","solutions":["Acquire a separate FileSystem per bucket: FileSystem.get(new URI(\"gs://bucket-b\"), conf) or path.getFileSystem(conf).","Use bucket-less (relative) paths so they qualify against the instance's root bucket.","Align job path configs with the bucket the FileSystem was initialized for (or configure per-bucket roots)."],"exampleFix":"// before\nFileSystem fsA = FileSystem.get(new URI(\"gs://bucket-a\"), conf);\nfsA.exists(new Path(\"gs://bucket-b/key\")); // IllegalArgumentException: Wrong bucket\n\n// after\nFileSystem fsB = FileSystem.get(new URI(\"gs://bucket-b\"), conf);\nfsB.exists(new Path(\"gs://bucket-b/key\"));","handlingStrategy":"validation","validationCode":"static boolean bucketOk(URI fsRoot, Path p) {\n  String b = p.toUri().getAuthority();\n  return b == null || b.equals(fsRoot.getAuthority());\n}","typeGuard":null,"tryCatchPattern":"catch IllegalArgumentException with message startsWith(\"Wrong bucket\") - acquire a FileSystem rooted at that bucket (FileSystem.get(new URI(\"gs://\" + bucket), conf)) and retry.","preventionTips":["One GoogleHadoopFileSystem instance serves exactly one bucket - never reuse a handle across buckets.","In multi-bucket pipelines, map bucket -> FileSystem explicitly.","Prefer bucket-less paths when operating within the instance's root bucket."],"tags":["path","gcs","hadoop","bucket","validation"],"backgroundTag":"filesystem-bucket-mismatch","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}