src/share/classes/java/lang/ClassLoader.java

Print this page




1829         }
1830         if (loader != null) {
1831             String libfilename = loader.findLibrary(name);
1832             if (libfilename != null) {
1833                 File libfile = new File(libfilename);
1834                 if (!libfile.isAbsolute()) {
1835                     throw new UnsatisfiedLinkError(
1836     "ClassLoader.findLibrary failed to return an absolute path: " + libfilename);
1837                 }
1838                 if (loadLibrary0(fromClass, libfile)) {
1839                     return;
1840                 }
1841                 throw new UnsatisfiedLinkError("Can't load " + libfilename);
1842             }
1843         }
1844         for (int i = 0 ; i < sys_paths.length ; i++) {
1845             File libfile = new File(sys_paths[i], System.mapLibraryName(name));
1846             if (loadLibrary0(fromClass, libfile)) {
1847                 return;
1848             }




1849         }
1850         if (loader != null) {
1851             for (int i = 0 ; i < usr_paths.length ; i++) {
1852                 File libfile = new File(usr_paths[i],
1853                                         System.mapLibraryName(name));
1854                 if (loadLibrary0(fromClass, libfile)) {
1855                     return;
1856                 }




1857             }
1858         }
1859         // Oops, it failed
1860         throw new UnsatisfiedLinkError("no " + name + " in java.library.path");
1861     }
1862 
1863     private static boolean loadLibrary0(Class fromClass, final File file) {
1864         boolean exists = AccessController.doPrivileged(
1865             new PrivilegedAction<Object>() {
1866                 public Object run() {
1867                     return file.exists() ? Boolean.TRUE : null;
1868                 }})
1869             != null;
1870         if (!exists) {
1871             return false;
1872         }
1873         String name;
1874         try {
1875             name = file.getCanonicalPath();
1876         } catch (IOException e) {




1829         }
1830         if (loader != null) {
1831             String libfilename = loader.findLibrary(name);
1832             if (libfilename != null) {
1833                 File libfile = new File(libfilename);
1834                 if (!libfile.isAbsolute()) {
1835                     throw new UnsatisfiedLinkError(
1836     "ClassLoader.findLibrary failed to return an absolute path: " + libfilename);
1837                 }
1838                 if (loadLibrary0(fromClass, libfile)) {
1839                     return;
1840                 }
1841                 throw new UnsatisfiedLinkError("Can't load " + libfilename);
1842             }
1843         }
1844         for (int i = 0 ; i < sys_paths.length ; i++) {
1845             File libfile = new File(sys_paths[i], System.mapLibraryName(name));
1846             if (loadLibrary0(fromClass, libfile)) {
1847                 return;
1848             }
1849             libfile = ClassLoaderHelper.mapAlternativeName(libfile);
1850             if (libfile != null && loadLibrary0(fromClass, libfile)) {
1851                 return;
1852             }
1853         }
1854         if (loader != null) {
1855             for (int i = 0 ; i < usr_paths.length ; i++) {
1856                 File libfile = new File(usr_paths[i],
1857                                         System.mapLibraryName(name));
1858                 if (loadLibrary0(fromClass, libfile)) {
1859                     return;
1860                 }
1861                 libfile = ClassLoaderHelper.mapAlternativeName(libfile);
1862                 if (libfile != null && loadLibrary0(fromClass, libfile)) {
1863                     return;
1864                 }
1865             }
1866         }
1867         // Oops, it failed
1868         throw new UnsatisfiedLinkError("no " + name + " in java.library.path");
1869     }
1870 
1871     private static boolean loadLibrary0(Class fromClass, final File file) {
1872         boolean exists = AccessController.doPrivileged(
1873             new PrivilegedAction<Object>() {
1874                 public Object run() {
1875                     return file.exists() ? Boolean.TRUE : null;
1876                 }})
1877             != null;
1878         if (!exists) {
1879             return false;
1880         }
1881         String name;
1882         try {
1883             name = file.getCanonicalPath();
1884         } catch (IOException e) {