Skip to content

Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance

fixed concurrentModificationException during hello-process

orbiter9a32a4c32856
diff --git a/htroot/yacy/hello.java b/htroot/yacy/hello.java
index 66733a88e..54ca87d8e 100644
--- a/htroot/yacy/hello.java
+++ b/htroot/yacy/hello.java
@@ -47,6 +47,7 @@
// if the shell's current path is HTROOT
import java.net.InetAddress;
+import java.util.ConcurrentModificationException;
import java.util.Iterator;
import java.util.Map;
@@ -210,10 +211,12 @@ public final class hello {
Iterator<yacySeed> si = ySeeds.values().iterator();
yacySeed s;
while (si.hasNext()) {
- s = (yacySeed) si.next();
- if ((s != null) && (s.isProper() == null)) {
+ s = si.next();
+ if ((s != null) && (s.isProper() == null)) try {
seeds.append("seed").append(count).append('=').append(s.genSeedStr(key)).append(serverCore.CRLF_STRING);
count++;
+ } catch (ConcurrentModificationException e) {
+ e.printStackTrace();
}
}
}
diff --git a/source/de/anomic/server/serverCodings.java b/source/de/anomic/server/serverCodings.java
index 28bb54900..a6320b045 100644
--- a/source/de/anomic/server/serverCodings.java
+++ b/source/de/anomic/server/serverCodings.java
@@ -195,18 +195,19 @@ public final class serverCodings {
}
public static String map2string(Map<String, String> m, String separator, boolean braces) {
- final StringBuffer buf = new StringBuffer(20 * m.size());
- if (braces) { buf.append("{"); }
- final Iterator<Map.Entry<String, String>> i = m.entrySet().iterator();
- while (i.hasNext()) {
- final Entry<String, String> e = i.next();
- buf.append(e.getKey()).append('=');
- if (e.getValue() != null) { buf.append(e.getValue()); }
- buf.append(separator);
+ // m must be synchronized to prevent that a ConcurrentModificationException occurs
+ synchronized (m) {
+ final StringBuffer buf = new StringBuffer(20 * m.size());
+ if (braces) { buf.append("{"); }
+ for (Entry<String, String> e: m.entrySet()) {
+ buf.append(e.getKey()).append('=');
+ if (e.getValue() != null) { buf.append(e.getValue()); }
+ buf.append(separator);
+ }
+ if (buf.length() > 1) { buf.setLength(buf.length() - 1); } // remove last separator
+ if (braces) { buf.append("}"); }
+ return new String(buf);
}
- if (buf.length() > 1) { buf.setLength(buf.length() - 1); } // remove last separator
- if (braces) { buf.append("}"); }
- return new String(buf);
}
public static Set<String> string2set(String string, String separator) {