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

Print this page
rev 11185 : [mq]: 8067951-System.loadLibrary.cannot.find.library.when.path.contains.quoted.entry

@@ -1749,11 +1749,11 @@
 
     private static String[] initializePath(String propname) {
         String ldpath = System.getProperty(propname, "");
         String ps = File.pathSeparator;
         int ldlen = ldpath.length();
-        int i, j, n;
+        int i, j, k, n;
         // Count the separators in the path
         i = ldpath.indexOf(ps);
         n = 0;
         while (i >= 0) {
             n++;

@@ -1762,22 +1762,29 @@
 
         // allocate the array of paths - n :'s = n + 1 path elements
         String[] paths = new String[n + 1];
 
         // Fill the array with paths from the ldpath
-        n = i = 0;
-        j = ldpath.indexOf(ps);
-        while (j >= 0) {
+        for (n = i = 0; n < paths.length; n++) {
+            j = ldpath.indexOf(ps, i);
+            if (j == -1) {
+                j = ldpath.length();
+            }
+            k = j;
+            if (j - i > 1 &&
+                    ldpath.charAt(i) == '\"' &&
+                    ldpath.charAt(j - 1) == '\"') {
+                i++;
+                j--;
+            }
             if (j - i > 0) {
-                paths[n++] = ldpath.substring(i, j);
-            } else if (j - i == 0) {
-                paths[n++] = ".";
+                paths[n] = ldpath.substring(i, j);
+            } else {
+                paths[n] = ".";
             }
-            i = j + 1;
-            j = ldpath.indexOf(ps, i);
+            i = k + 1;
         }
-        paths[n] = ldpath.substring(i, ldlen);
         return paths;
     }
 
     // Invoked in the java.lang.Runtime class to implement load and loadLibrary.
     static void loadLibrary(Class<?> fromClass, String name,