aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDeepak Bhole <[email protected]>2012-03-14 15:05:54 -0400
committerDeepak Bhole <[email protected]>2012-03-14 15:05:54 -0400
commit6b070376f754d27eb53536e6add664c860d742ce (patch)
treeb5b20287e15528acb8055e771e40563e2340be98
parentbf89d620ace4a20270fee72285f9c4c9bfa6b345 (diff)
PR895: IcedTea-Web searches for missing classes on each loadClass or findClass
-rw-r--r--ChangeLog15
-rw-r--r--NEWS1
-rw-r--r--netx/net/sourceforge/jnlp/runtime/JNLPClassLoader.java50
-rw-r--r--tests/netx/unit/net/sourceforge/jnlp/runtime/CodeBaseClassLoaderTest.java142
4 files changed, 204 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index 6201b36..eb7c28e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2012-03-14 Deepak Bhole <[email protected]>
+ Omair Majid <[email protected]>
+
+ PR895: IcedTea-Web searches for missing classes on each loadClass or
+ findClass
+ * netx/net/sourceforge/jnlp/runtime/JNLPClassLoader.java
+ (CodeBaseClassLoader): Added new map to track resources that are not
+ found.
+ (findClass): If resource was not found before, return immediately. If
+ resource was not found for the first time, record it in the new map.
+ (findResouces): Same.
+ (findResource): Same.
+ * tests/netx/unit/net/sourceforge/jnlp/runtime/CodeBaseClassLoaderTest.java:
+ Test case for PR895 from Omair Majid.
+
2012-03-14 Omair Majid <[email protected]>
Print exceptions to terminal when running in gui mode too.
diff --git a/NEWS b/NEWS
index a694a62..22a220e 100644
--- a/NEWS
+++ b/NEWS
@@ -11,6 +11,7 @@ CVE-XXXX-YYYY: http://www.cve.mitre.org/cgi-bin/cvename.cgi?name=XXXX-YYYY
New in release 1.3 (2012-XX-XX):
* Plugin
- PR820: IcedTea-Web 1.1.3 crashing Firefox when loading Citrix XenApp
+ - PR895: IcedTea-Web searches for missing classes on each loadClass or findClass
New in release 1.2 (2011-XX-XX):
* Security updates:
diff --git a/netx/net/sourceforge/jnlp/runtime/JNLPClassLoader.java b/netx/net/sourceforge/jnlp/runtime/JNLPClassLoader.java
index 1a1be71..cfca05d 100644
--- a/netx/net/sourceforge/jnlp/runtime/JNLPClassLoader.java
+++ b/netx/net/sourceforge/jnlp/runtime/JNLPClassLoader.java
@@ -37,6 +37,7 @@ import java.security.Permissions;
import java.security.PrivilegedAction;
import java.security.PrivilegedExceptionAction;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
@@ -47,9 +48,11 @@ import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import java.util.Vector;
+import java.util.concurrent.ConcurrentHashMap;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.jar.Manifest;
+
import net.sourceforge.jnlp.AppletDesc;
import net.sourceforge.jnlp.ApplicationDesc;
import net.sourceforge.jnlp.DownloadOptions;
@@ -1874,6 +1877,11 @@ public class JNLPClassLoader extends URLClassLoader {
JNLPClassLoader parentJNLPClassLoader;
+ /**
+ * Classes that are not found, so that findClass can skip them next time
+ */
+ ConcurrentHashMap<String, URL[]> notFoundResources = new ConcurrentHashMap<String, URL[]>();
+
public CodeBaseClassLoader(URL[] urls, JNLPClassLoader cl) {
super(urls);
parentJNLPClassLoader = cl;
@@ -1885,8 +1893,18 @@ public class JNLPClassLoader extends URLClassLoader {
}
@Override
- public Class<?> findClass(String name) throws ClassNotFoundException {
- return super.findClass(name);
+ public Class<?> findClass(String name) throws ClassNotFoundException {
+
+ // If we have searched this path before, don't try again
+ if (Arrays.equals(super.getURLs(), notFoundResources.get(name)))
+ throw new ClassNotFoundException(name);
+
+ try {
+ return super.findClass(name);
+ } catch (ClassNotFoundException cnfe) {
+ notFoundResources.put(name, super.getURLs());
+ throw cnfe;
+ }
}
/**
@@ -1913,17 +1931,41 @@ public class JNLPClassLoader extends URLClassLoader {
@Override
public Enumeration<URL> findResources(String name) throws IOException {
+
+ // If we have searched this path before, don't try again
+ if (Arrays.equals(super.getURLs(), notFoundResources.get(name)))
+ return (new Vector<URL>(0)).elements();
+
if (!name.startsWith("META-INF")) {
- return super.findResources(name);
+ Enumeration<URL> urls = super.findResources(name);
+
+ if (!urls.hasMoreElements()) {
+ notFoundResources.put(name, super.getURLs());
+ }
+
+ return urls;
}
+
return (new Vector<URL>(0)).elements();
}
@Override
public URL findResource(String name) {
+
+ // If we have searched this path before, don't try again
+ if (Arrays.equals(super.getURLs(), notFoundResources.get(name)))
+ return null;
+
if (!name.startsWith("META-INF")) {
- return super.findResource(name);
+ URL url = super.findResource(name);
+
+ if (url == null) {
+ notFoundResources.put(name, super.getURLs());
+ }
+
+ return url;
}
+
return null;
}
}
diff --git a/tests/netx/unit/net/sourceforge/jnlp/runtime/CodeBaseClassLoaderTest.java b/tests/netx/unit/net/sourceforge/jnlp/runtime/CodeBaseClassLoaderTest.java
new file mode 100644
index 0000000..f2ebc0e
--- /dev/null
+++ b/tests/netx/unit/net/sourceforge/jnlp/runtime/CodeBaseClassLoaderTest.java
@@ -0,0 +1,142 @@
+/* CodeBaseClassLoaderTest.java
+ Copyright (C) 2012 Red Hat, Inc.
+
+This file is part of IcedTea.
+
+IcedTea is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License as published by
+the Free Software Foundation, version 2.
+
+IcedTea is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with IcedTea; see the file COPYING. If not, write to
+the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version.
+*/
+
+package net.sourceforge.jnlp.runtime;
+
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.Locale;
+
+import net.sourceforge.jnlp.JNLPFile;
+import net.sourceforge.jnlp.LaunchException;
+import net.sourceforge.jnlp.ParseException;
+import net.sourceforge.jnlp.ResourcesDesc;
+import net.sourceforge.jnlp.SecurityDesc;
+import net.sourceforge.jnlp.runtime.JNLPClassLoader;
+import net.sourceforge.jnlp.runtime.JNLPClassLoader.CodeBaseClassLoader;
+
+import org.junit.Test;
+
+public class CodeBaseClassLoaderTest {
+
+ @Test
+ public void testResourceLoadSuccessCaching() throws LaunchException, ClassNotFoundException, IOException, ParseException {
+ final URL JAR_URL = new URL("http://icedtea.classpath.org/netx/about.jar");
+ final URL CODEBASE_URL = new URL("http://icedtea.classpath.org/netx/");
+
+ JNLPFile dummyJnlpFile = new JNLPFile() {
+ @Override
+ public ResourcesDesc getResources() {
+ return new ResourcesDesc(null, new Locale[0], new String[0], new String[0]);
+ }
+
+ @Override
+ public URL getCodeBase() {
+ return CODEBASE_URL;
+ }
+
+ @Override
+ public SecurityDesc getSecurity() {
+ return new SecurityDesc(null, SecurityDesc.SANDBOX_PERMISSIONS, null);
+ }
+ };
+
+ JNLPClassLoader parent = new JNLPClassLoader(dummyJnlpFile, null);
+ CodeBaseClassLoader classLoader = new CodeBaseClassLoader(new URL[] { JAR_URL, CODEBASE_URL }, parent);
+
+ long startTime, stopTime;
+
+ startTime = System.nanoTime();
+ classLoader.findResource("net/sourceforge/jnlp/about/Main.class");
+ stopTime = System.nanoTime();
+ long timeOnFirstTry = stopTime - startTime;
+ System.out.println(timeOnFirstTry);
+
+ startTime = System.nanoTime();
+ classLoader.findResource("net/sourceforge/jnlp/about/Main.class");
+ stopTime = System.nanoTime();
+ long timeOnSecondTry = stopTime - startTime;
+ System.out.println(timeOnSecondTry);
+
+ assertTrue(timeOnSecondTry < (timeOnFirstTry / 10));
+ }
+
+ @Test
+ public void testResourceLoadFailureCaching() throws LaunchException, ClassNotFoundException, IOException, ParseException {
+ final URL JAR_URL = new URL("http://icedtea.classpath.org/netx/about.jar");
+ final URL CODEBASE_URL = new URL("http://icedtea.classpath.org/netx/");
+
+ JNLPFile dummyJnlpFile = new JNLPFile() {
+ @Override
+ public ResourcesDesc getResources() {
+ return new ResourcesDesc(null, new Locale[0], new String[0], new String[0]);
+ }
+
+ @Override
+ public URL getCodeBase() {
+ return CODEBASE_URL;
+ }
+
+ @Override
+ public SecurityDesc getSecurity() {
+ return new SecurityDesc(null, SecurityDesc.SANDBOX_PERMISSIONS, null);
+ }
+ };
+
+ JNLPClassLoader parent = new JNLPClassLoader(dummyJnlpFile, null);
+ CodeBaseClassLoader classLoader = new CodeBaseClassLoader(new URL[] { JAR_URL, CODEBASE_URL }, parent);
+
+ long startTime, stopTime;
+
+ startTime = System.nanoTime();
+ classLoader.findResource("net/sourceforge/jnlp/about/Main_FOO_.class");
+ stopTime = System.nanoTime();
+ long timeOnFirstTry = stopTime - startTime;
+ System.out.println(timeOnFirstTry);
+
+ startTime = System.nanoTime();
+ classLoader.findResource("net/sourceforge/jnlp/about/Main_FOO_.class");
+ stopTime = System.nanoTime();
+ long timeOnSecondTry = stopTime - startTime;
+ System.out.println(timeOnSecondTry);
+
+ assertTrue(timeOnSecondTry < (timeOnFirstTry / 10));
+ }
+
+}