Skip to content

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

fix for NPE in seed handling

orbiterc6525ab75f51
diff --git a/source/de/anomic/yacy/yacySeed.java b/source/de/anomic/yacy/yacySeed.java
index 2baf3909a..e1e08c402 100644
--- a/source/de/anomic/yacy/yacySeed.java
+++ b/source/de/anomic/yacy/yacySeed.java
@@ -170,6 +170,7 @@ public class yacySeed implements Cloneable {
public yacySeed(final String theHash, final Map<String, String> theDna) {
// create a seed with a pre-defined hash map
+ assert theHash != null;
this.hash = theHash;
this.dna = theDna;
final String flags = this.dna.get(yacySeed.FLAGS);
@@ -901,6 +902,7 @@ public class yacySeed implements Cloneable {
// extract hash
final HashMap<String, String> dna = serverCodings.string2map(seed, ",");
final String hash = dna.remove(yacySeed.HASH);
+ if (hash == null) return null;
final yacySeed resultSeed = new yacySeed(hash, dna);
// check semantics of content
diff --git a/source/de/anomic/yacy/yacySeedDB.java b/source/de/anomic/yacy/yacySeedDB.java
index 79d5a61bc..19f5ef2c5 100644
--- a/source/de/anomic/yacy/yacySeedDB.java
+++ b/source/de/anomic/yacy/yacySeedDB.java
@@ -954,11 +954,13 @@ public final class yacySeedDB implements httpdAlternativeDomainNames {
public yacySeed internalNext() {
if ((it == null) || (!(it.hasNext()))) return null;
try {
- final Map<String, String> dna = it.next();
- if (dna == null) return null;
- final String hash = dna.remove("key");
- //while (hash.length() < commonHashLength) { hash = hash + "_"; }
- return new yacySeed(hash, dna);
+ while (true) {
+ final Map<String, String> dna = it.next();
+ if (dna == null) return null;
+ final String hash = dna.remove("key");
+ if (hash == null) { continue; } // bad seed
+ return new yacySeed(hash, dna);
+ }
} catch (final Exception e) {
e.printStackTrace();
yacyCore.log.logSevere("ERROR internalNext: seed.db corrupt (" + e.getMessage() + "); resetting seed.db", e);