lib/ext JAR file search order

Ioi Lam ioi.lam at
Fri Nov 15 20:37:24 UTC 2013

 From sun.misc.Launcher$ExtClassLoader:

         private static URL[] getExtURLs(File[] dirs) throws IOException {
             Vector<URL> urls = new Vector<URL>();
             for (int i = 0; i < dirs.length; i++) {
                 String[] files = dirs[i].list();
                 if (files != null) {
                     for (int j = 0; j < files.length; j++) {
                         if (!files[j].equals("meta-index")) {
                             File f = new File(dirs[i], files[j]);
             URL[] ua = new URL[urls.size()];
             return ua;

the search order is completely depending on the order of files returned 
by File.list(), whose Javadoc explictly says the order is not defined:

   "There is no guarantee that the name strings in the
    resulting array will appear in any specific order;
    they are not, in particular, guaranteed to appear
    in alphabetical order."

So, what happens when the same class file exists in two JAR files in 

- Ioi

More information about the core-libs-dev mailing list