{"record":{"id":"c5b033980fc7eba8","repo":"apache/hadoop","slug":"googlehadoopfilesystem-has-been-closed-or-not-init","errorCode":null,"errorMessage":"GoogleHadoopFileSystem has been closed or not initialized.","messagePattern":"GoogleHadoopFileSystem has been closed or not initialized\\.","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"hadoop-cloud-storage-project/hadoop-gcp/src/main/java/org/apache/hadoop/fs/gs/GoogleHadoopFileSystem.java","lineNumber":700,"sourceCode":"  @Override\n  public String getCanonicalServiceName() {\n    // TODO: Add delegation token support\n    return null;\n  }\n\n  /**\n   * Gets GCS FS instance.\n   */\n  GoogleCloudStorageFileSystem getGcsFs() {\n    return gcsFs;\n  }\n\n  /**\n   * Assert that the FileSystem has been initialized and not close()d.\n   */\n  private void checkOpen() throws IOException {\n    if (isClosed) {\n      throw new IOException(\"GoogleHadoopFileSystem has been closed or not initialized.\");\n    }\n  }\n\n  @Override\n  public void close() throws IOException {\n    LOG.trace(\"close()\");\n    if (isClosed) {\n      return;\n    }\n\n    super.close();\n\n    getGcsFs().close();\n\n    this.isClosed = true;\n  }\n\n  @Override","sourceCodeStart":682,"sourceCodeEnd":718,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-cloud-storage-project/hadoop-gcp/src/main/java/org/apache/hadoop/fs/gs/GoogleHadoopFileSystem.java#L682-L718","documentation":"GoogleHadoopFileSystem.checkOpen guards every operation with the isClosed flag and throws IOException('GoogleHadoopFileSystem has been closed or not initialized.') when the instance was close()d (or never completed initialize()). The message covers both lifecycle errors because the same flag defends both.","triggerScenarios":"Calling any FileSystem method (open, getFileStatus, rename, ...) on an instance after close(); using a manually constructed GoogleHadoopFileSystem without calling initialize(uri, conf); a shared cached instance closed by one job while another still uses it.","commonSituations":"Static/cached FileSystem handles in long-lived services where one shutdown path closes the shared instance; test code constructing the FS directly; job cleanup racing the next job's operations.","solutions":["Re-acquire the FileSystem after close: FileSystem.get(uri, conf) returns/creates a usable instance (or use FileSystem.newInstance for a private one).","Never cache a FileSystem across lifecycle boundaries; derive it from path.getFileSystem(conf) at use time.","If constructing directly, always call initialize(uri, conf) before any operation."],"exampleFix":"// before\nFileSystem fs = FileSystem.get(gcsUri, conf);\nfs.close();\nfs.open(path); // IOException: has been closed or not initialized.\n\n// after\nFileSystem fs = FileSystem.get(gcsUri, conf); // fresh usable instance\nfs.open(path);","handlingStrategy":"validation","validationCode":"FileSystem fs = path.getFileSystem(conf); // healthy per-use acquisition\n// or, after a close:\nFileSystem fresh = FileSystem.newInstance(gcsRootUri, conf);\nfresh.open(path);","typeGuard":null,"tryCatchPattern":"catch IOException with message equals(\"GoogleHadoopFileSystem has been closed or not initialized.\") - abandon the dead instance and re-acquire via FileSystem.get/newInstance; do not retry on the same object.","preventionTips":["Do not cache FileSystem instances across job/service lifecycles; obtain per use via path.getFileSystem(conf).","Never close a shared/cached FileSystem from cleanup code that other consumers still use.","When constructing directly (tests), always call initialize(uri, conf) first."],"tags":["lifecycle","gcs","hadoop","filesystem","initialization"],"backgroundTag":"filesystem-closed","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}