From 6d4e08ed06c5cd28c45981b2ebe31c7f7ec6fd83 Mon Sep 17 00:00:00 2001 From: Roland 'Quix0r' Haeder Date: Thu, 29 Dec 2011 03:42:38 +0100 Subject: [PATCH] Rewrote filesize() to (hopefully) avoid a NPE, rewrote Blacklist class to concurrent classes to avoid a CME --- source/net/yacy/kelondro/io/Records.java | 11 ++++++++++- source/net/yacy/repository/Blacklist.java | 9 ++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/source/net/yacy/kelondro/io/Records.java b/source/net/yacy/kelondro/io/Records.java index ad5abc60c..a22256891 100644 --- a/source/net/yacy/kelondro/io/Records.java +++ b/source/net/yacy/kelondro/io/Records.java @@ -157,7 +157,16 @@ public final class Records { * @throws IOException */ private final long filesize() throws IOException { - return raf.length() / recordsize; + long records = 0; + + try { + records = raf.length() / recordsize; + } catch (NullPointerException e) { + // This may happen on shutdown while still something is moving on + Log.logException(e); + } + + return records; } /** diff --git a/source/net/yacy/repository/Blacklist.java b/source/net/yacy/repository/Blacklist.java index f8162b653..7e4b6b9f6 100644 --- a/source/net/yacy/repository/Blacklist.java +++ b/source/net/yacy/repository/Blacklist.java @@ -29,7 +29,6 @@ import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; -import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.List; @@ -94,8 +93,8 @@ public class Blacklist { public static final String BLACKLIST_TYPES_STRING = "proxy,crawler,dht,search,surftips,news"; private File blacklistRootPath = null; private final ConcurrentMap cachedUrlHashs; - private final ConcurrentMap>> hostpaths_matchable; // key=host, value=path; mapped url is http://host/path; path does not start with '/' here - private final ConcurrentMap>> hostpaths_notmatchable; // key=host, value=path; mapped url is http://host/path; path does not start with '/' here + private final ConcurrentMap>> hostpaths_matchable; // key=host, value=path; mapped url is http://host/path; path does not start with '/' here + private final ConcurrentMap>> hostpaths_notmatchable; // key=host, value=path; mapped url is http://host/path; path does not start with '/' here public Blacklist(final File rootPath) { @@ -107,8 +106,8 @@ public class Blacklist { this.cachedUrlHashs = new ConcurrentHashMap(); for (final String blacklistType : BLACKLIST_TYPES) { - this.hostpaths_matchable.put(blacklistType, new HashMap>()); - this.hostpaths_notmatchable.put(blacklistType, new HashMap>()); + this.hostpaths_matchable.put(blacklistType, new ConcurrentHashMap>()); + this.hostpaths_notmatchable.put(blacklistType, new ConcurrentHashMap>()); this.cachedUrlHashs.put(blacklistType, new HandleSet(URIMetadataRow.rowdef.primaryKeyLength, URIMetadataRow.rowdef.objectOrder, 0)); } }