Index: modules/luni/src/main/java/java/net/URLClassLoader.java =================================================================== --- modules/luni/src/main/java/java/net/URLClassLoader.java (revision 500945) +++ modules/luni/src/main/java/java/net/URLClassLoader.java (working copy) @@ -170,7 +170,9 @@ URL search = createSearchURL(url); urls = addURL(urls, search); orgUrls = addURL(orgUrls, url); - extensions.put(search, null); + synchronized (extensions) { + extensions.put(search, null); + } } catch (MalformedURLException e) { } } @@ -703,25 +705,27 @@ URL currentUrl = searchList[i]; String protocol = currentUrl.getProtocol(); if (protocol.equals("jar")) { //$NON-NLS-1$ - jf = resCache.get(currentUrl); - if (jf == null) { - /* - * If the connection for currentUrl or resURL is - * used, getJarFile() will throw an exception if the - * entry doesn't exist. - */ - URL jarURL = ((JarURLConnection) currentUrl - .openConnection()).getJarFileURL(); - try { - JarURLConnection juc = (JarURLConnection) new URL( - "jar", "", //$NON-NLS-1$ //$NON-NLS-2$ - jarURL.toExternalForm() + "!/").openConnection(); //$NON-NLS-1$ - jf = juc.getJarFile(); - resCache.put(currentUrl, jf); - } catch (IOException e) { - // Don't look for this jar file again - invalidUrls.add(searchList[i]); - throw e; + synchronized (resCache) { + jf = resCache.get(currentUrl); + if (jf == null) { + /* + * If the connection for currentUrl or resURL is + * used, getJarFile() will throw an exception if the + * entry doesn't exist. + */ + URL jarURL = ((JarURLConnection) currentUrl + .openConnection()).getJarFileURL(); + try { + JarURLConnection juc = (JarURLConnection) new URL( + "jar", "", //$NON-NLS-1$ //$NON-NLS-2$ + jarURL.toExternalForm() + "!/").openConnection(); //$NON-NLS-1$ + jf = juc.getJarFile(); + resCache.put(currentUrl, jf); + } catch (IOException e) { + // Don't look for this jar file again + invalidUrls.add(searchList[i]); + throw e; + } } } String entryName; @@ -926,9 +930,11 @@ try { URL newURL = new URL(protocol, host, port, file + element + "!/"); //$NON-NLS-1$ - if (!extensions.containsKey(newURL)) { - extensions.put(newURL, null); - addedURLs.add(newURL); + synchronized (extensions) { + if (!extensions.containsKey(newURL)) { + extensions.put(newURL, null); + addedURLs.add(newURL); + } } } catch (MalformedURLException e) { // Nothing is added @@ -1008,23 +1014,25 @@ URL thisURL = searchURLs[i]; String protocol = thisURL.getProtocol(); if (protocol.equals("jar")) { //$NON-NLS-1$ - jf = resCache.get(thisURL); - if (jf == null) { - // If the connection for testURL or thisURL is used, - // getJarFile() will throw an exception if the entry - // doesn't exist. - URL jarURL = ((JarURLConnection) thisURL - .openConnection()).getJarFileURL(); - try { - JarURLConnection juc = (JarURLConnection) new URL( - "jar", "", jarURL.toExternalForm() + "!/") //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - .openConnection(); - jf = juc.getJarFile(); - resCache.put(thisURL, jf); - } catch (IOException e) { - // Don't look for this jar file again - invalidUrls.add(searchURLs[i]); - throw e; + synchronized (resCache) { + jf = resCache.get(thisURL); + if (jf == null) { + // If the connection for testURL or thisURL is used, + // getJarFile() will throw an exception if the entry + // doesn't exist. + URL jarURL = ((JarURLConnection) thisURL + .openConnection()).getJarFileURL(); + try { + JarURLConnection juc = (JarURLConnection) new URL( + "jar", "", jarURL.toExternalForm() + "!/") //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + .openConnection(); + jf = juc.getJarFile(); + resCache.put(thisURL, jf); + } catch (IOException e) { + // Don't look for this jar file again + invalidUrls.add(searchURLs[i]); + throw e; + } } } if (thisURL.getFile().endsWith("!/")) { //$NON-NLS-1$