* Clone System properties before iterating to avoid

ConcurrentModificationException (ticket #680)
This commit is contained in:
zzz
2012-08-06 14:45:37 +00:00
parent 91e61dbd5c
commit 1ab8200c7f
7 changed files with 23 additions and 15 deletions

View File

@ -6,6 +6,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Constructor;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
import net.i2p.I2PAppContext;
@ -36,7 +37,7 @@ public class I2PSocketManagerFactory {
* @return the newly created socket manager, or null if there were errors
*/
public static I2PSocketManager createManager() {
return createManager(getHost(), getPort(), System.getProperties());
return createManager(getHost(), getPort(), (Properties) System.getProperties().clone());
}
/**
@ -59,7 +60,7 @@ public class I2PSocketManagerFactory {
* @return the newly created socket manager, or null if there were errors
*/
public static I2PSocketManager createManager(String host, int port) {
return createManager(host, port, System.getProperties());
return createManager(host, port, (Properties) System.getProperties().clone());
}
/**
@ -95,7 +96,7 @@ public class I2PSocketManagerFactory {
* @return the newly created socket manager, or null if there were errors
*/
public static I2PSocketManager createManager(InputStream myPrivateKeyStream) {
return createManager(myPrivateKeyStream, getHost(), getPort(), System.getProperties());
return createManager(myPrivateKeyStream, getHost(), getPort(), (Properties) System.getProperties().clone());
}
/**
@ -126,10 +127,11 @@ public class I2PSocketManagerFactory {
I2PClient client = I2PClientFactory.createClient();
if (opts == null)
opts = new Properties();
for (Iterator iter = System.getProperties().keySet().iterator(); iter.hasNext(); ) {
String name = (String)iter.next();
Properties syscopy = (Properties) System.getProperties().clone();
for (Map.Entry e : syscopy.entrySet()) {
String name = (String) e.getKey();
if (!opts.containsKey(name))
opts.setProperty(name, System.getProperty(name));
opts.setProperty(name, (String) e.getValue());
}
//boolean oldLib = DEFAULT_MANAGER.equals(opts.getProperty(PROP_MANAGER, DEFAULT_MANAGER));
//if (oldLib && false) {

View File

@ -124,8 +124,7 @@ public class SAMStreamSession {
_log.debug("SAM STREAM session instantiated");
Properties allprops = new Properties();
allprops.putAll(System.getProperties());
Properties allprops = (Properties) System.getProperties().clone();
allprops.putAll(props);
String i2cpHost = allprops.getProperty(I2PClient.PROP_TCP_HOST, "127.0.0.1");

View File

@ -85,8 +85,7 @@ public class SAMv3StreamSession extends SAMStreamSession implements SAMv3Handle
_log.debug("SAM STREAM session instantiated");
Properties allprops = new Properties();
allprops.putAll(System.getProperties());
Properties allprops = (Properties) System.getProperties().clone();
allprops.putAll(rec.getProps());
String i2cpHost = allprops.getProperty(I2PClient.PROP_TCP_HOST, "127.0.0.1");

View File

@ -516,7 +516,8 @@ public class I2PAppContext {
* @return set of Strings containing the names of defined system properties
*/
public Set getPropertyNames() {
Set names = new HashSet(System.getProperties().keySet());
// clone to avoid ConcurrentModificationException
Set names = new HashSet(((Properties) System.getProperties().clone()).keySet());
if (_overrideProps != null)
names.addAll(_overrideProps.keySet());
return names;
@ -531,8 +532,8 @@ public class I2PAppContext {
* @since 0.8.4
*/
public Properties getProperties() {
Properties rv = new Properties();
rv.putAll(System.getProperties());
// clone to avoid ConcurrentModificationException
Properties rv = (Properties) System.getProperties().clone();
rv.putAll(_overrideProps);
return rv;
}

View File

@ -164,7 +164,7 @@ abstract class I2PSessionImpl implements I2PSession, I2CPMessageReader.I2CPMessa
_log = context.logManager().getLog(getClass());
_closed = true;
if (options == null)
options = System.getProperties();
options = (Properties) System.getProperties().clone();
loadConfig(options);
}

View File

@ -1,3 +1,10 @@
2012-08-06 zzz
* Clone System properties before iterating to avoid
ConcurrentModificationException (ticket #680)
* Console: Fix flag links on /console to return to same page
* i2psnark: Add support for DHT (disabled by default)
* jbigi: Add ARMv6 libjbigi.so for Raspberry Pi
2012-08-05 zzz
* I2PSessionImpl: One more volatile (ticket #659)
* i2ptunnel, I2CP, EepGet: Buffer socket input streams (ticket #666)

View File

@ -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 = 3;
public final static long BUILD = 4;
/** for example "-test" */
public final static String EXTRA = "";