code: public <C extends Closeable> C register(C resource) {
      // Initial open check to avoid incrementing registering if we already know it's closed.
      // This is to prevent any possibility of a weird pathalogical situation where the do/while
      // loop in close() keeps looping as register() is called repeatedly from multiple threads.
      checkOpen();
  
      registering.incrementAndGet();
      try {
        // Need to check again after marking registration in progress to avoid a potential race.
        // (close() could have run completely between the first checkOpen() and
        // registering.incrementAndGet().)
        checkOpen();
        resources.add(resource);
        return resource;
      } finally {
        registering.decrementAndGet();
      }
    }
docs: Registers the given resource to be closed when the file system is closed. Should be called when
  the resource is opened.