Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
yuqi1129 committed Oct 16, 2024
1 parent 35cba1e commit bcf2f12
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,7 @@ FileSystem getFileSystem(Path path, Map<String, String> config) throws IOExcepti
if (provider == null) {
throw new IllegalArgumentException(
String.format(
"Unsupported scheme: %s, path: %s, all supported scheme: %s and provider: %s",
"Unsupported scheme: %s, path: %s, all supported schemes: %s and providers: %s",
scheme, path, fileSystemProvidersMap.keySet(), fileSystemProvidersMap.values()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.google.common.collect.Sets;
import com.google.common.collect.Streams;
import java.util.Arrays;
import java.util.Locale;
import java.util.Map;
import java.util.ServiceLoader;
import java.util.Set;
Expand All @@ -42,18 +43,20 @@ public static Map<String, FileSystemProvider> getFileSystemProviders(String file
Set<String> providersInUses =
fileSystemProviders != null
? Arrays.stream(fileSystemProviders.split(","))
.map(String::trim)
.map(f -> f.trim().toLowerCase(Locale.ROOT))
.collect(java.util.stream.Collectors.toSet())
: Sets.newHashSet();

// Add built-in file system providers to the use list automatically.
providersInUses.add(BUILTIN_LOCAL_FS_PROVIDER);
providersInUses.add(BUILTIN_HDFS_FS_PROVIDER);
providersInUses.add(BUILTIN_LOCAL_FS_PROVIDER.toLowerCase(Locale.ROOT));
providersInUses.add(BUILTIN_HDFS_FS_PROVIDER.toLowerCase(Locale.ROOT));

// Only get the file system providers that are in the user list and check if the scheme is
// unique.
Streams.stream(allFileSystemProviders.iterator())
.filter(fileSystemProvider -> providersInUses.contains(fileSystemProvider.name()))
.filter(
fileSystemProvider ->
providersInUses.contains(fileSystemProvider.name().toLowerCase(Locale.ROOT)))
.forEach(
fileSystemProvider -> {
if (resultMap.containsKey(fileSystemProvider.scheme())) {
Expand All @@ -71,7 +74,7 @@ public static Map<String, FileSystemProvider> getFileSystemProviders(String file
Sets.difference(
providersInUses,
resultMap.values().stream()
.map(FileSystemProvider::name)
.map(p -> p.name().toLowerCase(Locale.ROOT))
.collect(Collectors.toSet()))
.immutableCopy();
if (!notFoundProviders.isEmpty()) {
Expand All @@ -91,6 +94,11 @@ public static FileSystemProvider getFileSystemProviderByName(
.filter(entry -> entry.getValue().name().equals(fileSystemProviderName))
.map(Map.Entry::getValue)
.findFirst()
.orElse(null);
.orElseThrow(
() ->
new UnsupportedOperationException(
String.format(
"File system provider with name '%s' not found in the file system provider list.",
fileSystemProviderName)));
}
}

0 comments on commit bcf2f12

Please sign in to comment.