Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java.nio.file.FileSystemNotFoundException on FileSystems.getFileSystem #716

Closed
stefanofornari opened this issue May 31, 2023 · 3 comments · Fixed by #717
Closed

java.nio.file.FileSystemNotFoundException on FileSystems.getFileSystem #716

stefanofornari opened this issue May 31, 2023 · 3 comments · Fixed by #717
Labels
bug Something isn't working
Milestone

Comments

@stefanofornari
Copy link

stefanofornari commented May 31, 2023

Bug Description

FileSystems.getFileSystem() throws a FileSystemNotFoundException if the file system has not been created before. This could be acceptable if FileSystems.newFileSystem(URI.create(file), new HashMap<>()) would be smart enough to return an existing FS if already created. Instead newFileSystem() throws a FileSystemAlreadyExistsException if called twice.
Alternatively, getFileSystem could return null, so to allow the pattern below (which now does not work):

FileSystem fs = FileSystems.getFileSystem(URI.create(file));
if (fs == null) {
        fs = FileSystems.newFileSystem(URI.create(file), new HashMap<>());
}

Steps To Reproduce

see description

Expected Behavior

  • getFileSystem() returns a new FileSystem if not already created?
  • getFileSystem() returns null?
  • newFileSystem() returns an existing FS if already created?

Environment

  • s3fs-nio version: 1.0.0 (also 1.0.1)
@stefanofornari stefanofornari added bug Something isn't working needs triage The issue needs to be triaged, before work can commence labels May 31, 2023
@steve-todorov steve-todorov removed the needs triage The issue needs to be triaged, before work can commence label Jun 4, 2023
@steve-todorov
Copy link
Collaborator

Hey @stefanofornari ,

Thanks for reporting this.

There is a bug left in some of the legacy code we've inherited. It was preventing an internal property's state to be visible from other threads and this messed up the getFileSystem method logic. I believe this should be fixed with #717. Could you try it out and let me know?

Your suggestion for returning null is not possible because it contradicts the java.nio.file.FileSystems#getFileSystem method's documentation:

image

Furthermore, the FileSystems method is a final one so we can't really change anything.
You can wrap your code in a try/catch that catches java.nio.file.ProviderNotFoundException instead of doing a null check and you'll achieve the same result :)

@steve-todorov steve-todorov added this to the 1.0.2 milestone Jun 4, 2023
@stefanofornari
Copy link
Author

stefanofornari commented Jun 5, 2023

Hi Steve, thanks, I will give it a try and let you know.

Furthermore, the FileSystems method is a final one so we can't really change anything.

I did not mean to extend FileSystems, but to fix the implementation in s3fs-nio provider.

@steve-todorov
Copy link
Collaborator

My bad then. Anyway let me know if this fixes it :)

@carlspring carlspring added the help wanted Extra attention is needed label Jun 6, 2023
@steve-todorov steve-todorov removed the help wanted Extra attention is needed label Jun 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants