src/share/classes/sun/misc/Launcher.java

Print this page
rev 9051 : 6760902: inconsistent behavior in system class loader for classes and resources
Reviewed-by: duke

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.  Oracle designates this

@@ -264,11 +264,11 @@
 
         public static ClassLoader getAppClassLoader(final ClassLoader extcl)
             throws IOException
         {
             final String s = System.getProperty("java.class.path");
-            final File[] path = (s == null) ? new File[0] : getClassPath(s);
+            final File[] path = (s == null) ? new File[0] : getClassPath(s, true);
 
             // Note: on bugid 4256530
             // Prior implementations of this doPrivileged() block supplied
             // a rather restrictive ACC via a call to the private method
             // AppClassLoader.getContext(). This proved overly restrictive

@@ -320,11 +320,11 @@
 
         /**
          * This class loader supports dynamic additions to the class path
          * at runtime.
          *
-         * @see java.lang.instrument.Instrumentation#appendToSystemClassPathSearch
+         * @see java.lang.instrument.Instrumentation#appendToSystemClassLoaderSearch
          */
         private void appendToClassPathForInstrumentation(String path) {
             assert(Thread.holdsLock(this));
 
             // addURL is a no-op if path already contains the URL

@@ -362,11 +362,12 @@
             URL[] urls;
             if (bootClassPath != null) {
                 urls = AccessController.doPrivileged(
                     new PrivilegedAction<URL[]>() {
                         public URL[] run() {
-                            File[] classPath = getClassPath(bootClassPath);
+                            // Skip empty path in boot class path i.e. not default to use CWD
+                            File[] classPath = getClassPath(bootClassPath, false);
                             int len = classPath.length;
                             Set<File> seenDirs = new HashSet<File>();
                             for (int i = 0; i < len; i++) {
                                 File curEntry = classPath[i];
                                 // Negative test used to properly handle

@@ -403,11 +404,11 @@
         //  System.out.println("urls[" + i + "] = " + '"' + urls[i] + '"');
         //}
         return urls;
     }
 
-    private static File[] getClassPath(String cp) {
+    private static File[] getClassPath(String cp, boolean defaultToCwd) {
         File[] path;
         if (cp != null) {
             int count = 0, maxCount = 1;
             int pos = 0, lastPos = 0;
             // Count the number of separators first

@@ -417,22 +418,22 @@
             }
             path = new File[maxCount];
             lastPos = pos = 0;
             // Now scan for each path component
             while ((pos = cp.indexOf(File.pathSeparator, lastPos)) != -1) {
-                if (pos - lastPos > 0) {
+                if (pos > lastPos) {
                     path[count++] = new File(cp.substring(lastPos, pos));
-                } else {
+                } else if (defaultToCwd) {
                     // empty path component translates to "."
                     path[count++] = new File(".");
                 }
                 lastPos = pos + 1;
             }
             // Make sure we include the last path component
             if (lastPos < cp.length()) {
                 path[count++] = new File(cp.substring(lastPos));
-            } else {
+            } else if (defaultToCwd) {
                 path[count++] = new File(".");
             }
             // Trim array to correct size
             if (count != maxCount) {
                 File[] tmp = new File[count];