src/java.base/share/classes/java/nio/file/FileSystems.java

Print this page
rev 12534 : 8132497: (fs) FileSystems.newFileSystem(URI, ..) doesn't handle UOE thrown by provider
Summary: Handle UOEs in newFileSystem(URI,...) similarly to as done in newFileSystem(Path path, ClassLoader loader).
Reviewed-by: chegar
   1 /*
   2  * Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 304      *          by the provider, or a property value is invalid
 305      * @throws  FileSystemAlreadyExistsException
 306      *          if the URI scheme identifies an installed provider and the file
 307      *          system has already been created
 308      * @throws  ProviderNotFoundException
 309      *          if a provider supporting the URI scheme is not found
 310      * @throws  ServiceConfigurationError
 311      *          when an error occurs while loading a service provider
 312      * @throws  IOException
 313      *          an I/O error occurs creating the file system
 314      * @throws  SecurityException
 315      *          if a security manager is installed and it denies an unspecified
 316      *          permission required by the file system provider implementation
 317      */
 318     public static FileSystem newFileSystem(URI uri, Map<String,?> env, ClassLoader loader)
 319         throws IOException
 320     {
 321         String scheme = uri.getScheme();
 322 
 323         // check installed providers
 324         for (FileSystemProvider provider: FileSystemProvider.installedProviders()) {
 325             if (scheme.equalsIgnoreCase(provider.getScheme())) {

 326                 return provider.newFileSystem(uri, env);


 327             }
 328         }
 329 
 330         // if not found, use service-provider loading facility
 331         if (loader != null) {
 332             ServiceLoader<FileSystemProvider> sl = ServiceLoader
 333                 .load(FileSystemProvider.class, loader);
 334             for (FileSystemProvider provider: sl) {
 335                 if (scheme.equalsIgnoreCase(provider.getScheme())) {

 336                     return provider.newFileSystem(uri, env);


 337                 }
 338             }
 339         }
 340 
 341         throw new ProviderNotFoundException("Provider \"" + scheme + "\" not found");
 342     }
 343 
 344     /**
 345      * Constructs a new {@code FileSystem} to access the contents of a file as a
 346      * file system.
 347      *
 348      * <p> This method makes use of specialized providers that create pseudo file
 349      * systems where the contents of one or more files is treated as a file
 350      * system.
 351      *
 352      * <p> This method iterates over the {@link FileSystemProvider#installedProviders()
 353      * installed} providers. It invokes, in turn, each provider's {@link
 354      * FileSystemProvider#newFileSystem(Path,Map) newFileSystem(Path,Map)} method
 355      * with an empty map. If a provider returns a file system then the iteration
 356      * terminates and the file system is returned. If none of the installed


   1 /*
   2  * Copyright (c) 2007, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 304      *          by the provider, or a property value is invalid
 305      * @throws  FileSystemAlreadyExistsException
 306      *          if the URI scheme identifies an installed provider and the file
 307      *          system has already been created
 308      * @throws  ProviderNotFoundException
 309      *          if a provider supporting the URI scheme is not found
 310      * @throws  ServiceConfigurationError
 311      *          when an error occurs while loading a service provider
 312      * @throws  IOException
 313      *          an I/O error occurs creating the file system
 314      * @throws  SecurityException
 315      *          if a security manager is installed and it denies an unspecified
 316      *          permission required by the file system provider implementation
 317      */
 318     public static FileSystem newFileSystem(URI uri, Map<String,?> env, ClassLoader loader)
 319         throws IOException
 320     {
 321         String scheme = uri.getScheme();
 322 
 323         // check installed providers
 324         for (FileSystemProvider provider : FileSystemProvider.installedProviders()) {
 325             if (scheme.equalsIgnoreCase(provider.getScheme())) {
 326                 try {
 327                     return provider.newFileSystem(uri, env);
 328                 } catch (UnsupportedOperationException uoe) {
 329                 }
 330             }
 331         }
 332 
 333         // if not found, use service-provider loading facility
 334         if (loader != null) {
 335             ServiceLoader<FileSystemProvider> sl = ServiceLoader
 336                 .load(FileSystemProvider.class, loader);
 337             for (FileSystemProvider provider : sl) {
 338                 if (scheme.equalsIgnoreCase(provider.getScheme())) {
 339                     try {
 340                         return provider.newFileSystem(uri, env);
 341                     } catch (UnsupportedOperationException uoe) {
 342                     }
 343                 }
 344             }
 345         }
 346 
 347         throw new ProviderNotFoundException("Provider \"" + scheme + "\" not found");
 348     }
 349 
 350     /**
 351      * Constructs a new {@code FileSystem} to access the contents of a file as a
 352      * file system.
 353      *
 354      * <p> This method makes use of specialized providers that create pseudo file
 355      * systems where the contents of one or more files is treated as a file
 356      * system.
 357      *
 358      * <p> This method iterates over the {@link FileSystemProvider#installedProviders()
 359      * installed} providers. It invokes, in turn, each provider's {@link
 360      * FileSystemProvider#newFileSystem(Path,Map) newFileSystem(Path,Map)} method
 361      * with an empty map. If a provider returns a file system then the iteration
 362      * terminates and the file system is returned. If none of the installed