From 0cea3e03aee5ff455bbc56e8696f82f0388cb3a6 Mon Sep 17 00:00:00 2001 From: zzz Date: Tue, 6 Mar 2012 14:04:04 +0000 Subject: [PATCH] * Webapp class loader: Fix dup classes in classpath caused by last checkin (symptom: i2psnark in wrong directory) --- .../i2p/router/web/WebAppConfiguration.java | 27 +++++++++++++++++++ history.txt | 9 +++++++ .../src/net/i2p/router/RouterVersion.java | 2 +- 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/apps/routerconsole/java/src/net/i2p/router/web/WebAppConfiguration.java b/apps/routerconsole/java/src/net/i2p/router/web/WebAppConfiguration.java index ac84d937a..7d3aee065 100644 --- a/apps/routerconsole/java/src/net/i2p/router/web/WebAppConfiguration.java +++ b/apps/routerconsole/java/src/net/i2p/router/web/WebAppConfiguration.java @@ -1,7 +1,11 @@ package net.i2p.router.web; import java.io.File; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.HashSet; import java.util.Properties; +import java.util.Set; import java.util.StringTokenizer; import net.i2p.I2PAppContext; @@ -83,6 +87,7 @@ public class WebAppConfiguration implements Configuration { return; StringTokenizer tok = new StringTokenizer(cp, " ,"); StringBuilder buf = new StringBuilder(); + Set systemCP = getSystemClassPath(); while (tok.hasMoreTokens()) { if (buf.length() > 0) buf.append(','); @@ -94,9 +99,20 @@ public class WebAppConfiguration implements Configuration { path = dir.getAbsolutePath() + elem.substring(7); else path = dir.getAbsolutePath() + '/' + elem; + // As of Jetty 6, we can't add dups to the class path, or + // else it screws up statics + File jfile = new File(path); + File jdir = jfile.getParentFile(); + if (systemCP.contains(jfile.toURI().toURL()) || + (jdir != null && systemCP.contains(jdir.toURI().toURL()))) { + //System.err.println("Not adding " + path + " to classpath for " + appName + ", already in system classpath"); + continue; + } System.err.println("Adding " + path + " to classpath for " + appName); buf.append(path); } + if (buf.length() <= 0) + return; ClassLoader cl = _wac.getClassLoader(); if (cl != null && cl instanceof WebAppClassLoader) { WebAppClassLoader wacl = (WebAppClassLoader) cl; @@ -109,6 +125,17 @@ public class WebAppConfiguration implements Configuration { } } + /** @since 0.9 */ + private static Set getSystemClassPath() { + URLClassLoader urlClassLoader = (URLClassLoader) ClassLoader.getSystemClassLoader(); + URL urls[] = urlClassLoader.getURLs(); + Set rv = new HashSet(32); + for (int i = 0; i < urls.length; i++) { + rv.add(urls[i]); + } + return rv; + } + public void configureDefaults() {} public void configureWebApp() {} diff --git a/history.txt b/history.txt index 1708a62ce..98d87d22d 100644 --- a/history.txt +++ b/history.txt @@ -1,3 +1,12 @@ +2012-03-06 zzz + * i2psnark: Fix NPE on magnet link addition + * Jetty logger: Fix stack trace logging + * viewstat.jsp: Properly close the ImageOutputStream to fix + NPEs in the finalizer, probably was the root cause of + what we blamed on Jetty + * Webapp class loader: Fix dup classes in classpath + caused by last checkin (symptom: i2psnark in wrong directory) + 2012-03-05 zzz * Build: Make windows and non-windows installers for release * configclients: Tweaks diff --git a/router/java/src/net/i2p/router/RouterVersion.java b/router/java/src/net/i2p/router/RouterVersion.java index 4e28a2c8d..c10128fe6 100644 --- a/router/java/src/net/i2p/router/RouterVersion.java +++ b/router/java/src/net/i2p/router/RouterVersion.java @@ -18,7 +18,7 @@ public class RouterVersion { /** deprecated */ public final static String ID = "Monotone"; public final static String VERSION = CoreVersion.VERSION; - public final static long BUILD = 5; + public final static long BUILD = 6; /** for example "-test" */ public final static String EXTRA = "";