{"record":{"id":"c59689ba182ef9b3","repo":"apache/hadoop","slug":"wrong-scheme-s-in-path-s-expected-scheme-s","errorCode":null,"errorMessage":"Wrong scheme: %s, in path: %s, expected scheme: %s","messagePattern":"Wrong scheme: (.+?), in path: (.+?), expected scheme: (.+?)","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":224,"sourceCode":"  private GoogleCredentials getCredentials(GoogleHadoopFileSystemConfiguration config)\n      throws IOException {\n    return getCredentials(config, GCS_CONFIG_PREFIX);\n  }\n\n  static GoogleCredentials getCredentials(GoogleHadoopFileSystemConfiguration config,\n      String... keyPrefixesVararg) throws IOException {\n    return HadoopCredentialsConfiguration.getCredentials(config.getConfig(), keyPrefixesVararg);\n  }\n\n  @Override\n  protected void checkPath(final Path path) {\n    LOG.trace(\"checkPath(path: {})\", path);\n    // 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  /**","sourceCodeStart":206,"sourceCodeEnd":242,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-cloud-storage-project/hadoop-gcp/src/main/java/org/apache/hadoop/fs/gs/GoogleHadoopFileSystem.java#L206-L242","documentation":"GoogleHadoopFileSystem.checkPath validates the scheme of every Path handed to this FileSystem instance: if the path carries a non-null scheme that does not case-insensitively equal the connector's scheme (gs), it throws IllegalArgumentException. This fires before any GCS call, as part of Hadoop's path-qualification contract.","triggerScenarios":"fs.open(new Path(\"s3a://bucket/key\")) or any operation on an hdfs://file:// path via a GoogleHadoopFileSystem instance; paths parsed from user input or config that retain their original scheme.","commonSituations":"Configs mixing cloud providers (fs.defaultFS set to one store while job paths point at another); copy-paste between S3 and GCS setups; Paths constructed from external strings without stripping the scheme.","solutions":["Use gs:// URIs (or scheme-less relative paths, which get qualified against the FileSystem root).","Route each path to its own FileSystem via path.getFileSystem(conf) instead of reusing one instance.","Normalize/strip schemes from user-supplied paths before passing them to a specific FileSystem."],"exampleFix":"// before\nFileSystem fs = FileSystem.get(new URI(\"gs://bucket\"), conf);\nfs.exists(new Path(\"s3a://bucket/key\")); // IllegalArgumentException: Wrong scheme\n\n// after\nfs.exists(new Path(\"gs://bucket/key\"));\n// or: new Path(\"s3a://bucket/key\").getFileSystem(conf) for the right store","handlingStrategy":"validation","validationCode":"static boolean schemeOk(FileSystem fs, Path p) {\n  String s = p.toUri().getScheme();\n  return s == null || s.equalsIgnoreCase(fs.getScheme());\n}\n// use: if (schemeOk(fs, path)) fs.open(path); else path.getFileSystem(conf)...","typeGuard":"static boolean isGcsPath(Path p) {\n  String s = p.toUri().getScheme();\n  return s == null || \"gs\".equalsIgnoreCase(s);\n}","tryCatchPattern":"catch IllegalArgumentException with message startsWith(\"Wrong scheme\") - fix the path's scheme or route it to path.getFileSystem(conf); retrying unchanged will always fail.","preventionTips":["Derive FileSystem per path (path.getFileSystem(conf)) in multi-store code.","Prefer scheme-less paths qualified against a known fs root.","Validate schemes of externally supplied paths at the trust boundary."],"tags":["path","gcs","hadoop","scheme","validation"],"backgroundTag":"filesystem-scheme-mismatch","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}