From 753a1ae4305659d24a6bb32b51dbc47e5b2e5954 Mon Sep 17 00:00:00 2001 From: danielr Date: Wed, 20 Aug 2008 07:54:56 +0000 Subject: [PATCH] - changed default browser from netscape to firefox - fixed "Inefficient use of keySet iterator instead of entrySet iterator" [WMI_WRONG_MAP_ITERATOR, FindBugs] - fixed some possible null pointer accesses git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@5063 6c8d7289-2bf4-0310-a012-ef5d649a1542 --- defaults/yacy.init | 2 +- htroot/BlacklistCleaner_p.java | 8 +++---- htroot/IndexShare_p.java | 13 +++++++++-- htroot/News.java | 10 ++++----- htroot/Ranking_p.java | 15 +++++++------ htroot/Threaddump_p.java | 7 ++++-- htroot/yacy/hello.java | 2 +- source/de/anomic/data/bookmarksDB.java | 8 +++---- source/de/anomic/data/userDB.java | 5 ++--- source/de/anomic/http/httpHeader.java | 8 ++----- .../index/indexDefaultReferenceBlacklist.java | 8 ++++--- .../de/anomic/kelondro/kelondroMSetTools.java | 8 +++---- source/de/anomic/plasma/plasmaParser.java | 8 +++---- .../de/anomic/plasma/plasmaSwitchboard.java | 12 +++++----- source/de/anomic/plasma/plasmaWordIndex.java | 2 +- source/de/anomic/server/serverCore.java | 6 ++--- source/de/anomic/server/serverObjects.java | 22 +++++++------------ source/de/anomic/server/serverSystem.java | 3 ++- source/de/anomic/yacy/yacyPeerActions.java | 1 - source/yacy.java | 2 +- 20 files changed, 77 insertions(+), 73 deletions(-) diff --git a/defaults/yacy.init b/defaults/yacy.init index 0731e86aa..4a28d0362 100644 --- a/defaults/yacy.init +++ b/defaults/yacy.init @@ -452,7 +452,7 @@ staticIP= # the browser type is optional and works only under certain conditions browserPopUpTrigger=true browserPopUpPage=ConfigBasic.html -browserPopUpApplication=netscape +browserPopUpApplication=firefox # defines if the YaCy icon appears in the system tray on supported platforms trayIcon=true diff --git a/htroot/BlacklistCleaner_p.java b/htroot/BlacklistCleaner_p.java index d8aced78d..7af740b6e 100644 --- a/htroot/BlacklistCleaner_p.java +++ b/htroot/BlacklistCleaner_p.java @@ -39,6 +39,7 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.Map; +import java.util.Map.Entry; import java.util.regex.Pattern; import java.util.regex.PatternSyntaxException; @@ -114,12 +115,11 @@ public class BlacklistCleaner_p { prop.put(RESULTS + "disabled", (ies.size() == 0) ? "1" : "0"); if (ies.size() > 0) { prop.put(RESULTS + DISABLED + "entries", ies.size()); - final Iterator it = ies.keySet().iterator(); int i = 0; String s; - while (it.hasNext()) { - s = it.next(); - prop.put(RESULTS + DISABLED + ENTRIES + i + "_error", ies.get(s).longValue()); + for (Entry entry: ies.entrySet()) { + s = entry.getKey(); + prop.put(RESULTS + DISABLED + ENTRIES + i + "_error", entry.getValue().longValue()); prop.putHTML(RESULTS + DISABLED + ENTRIES + i + "_entry", s); i++; } diff --git a/htroot/IndexShare_p.java b/htroot/IndexShare_p.java index a5851e9a7..f5aab120c 100644 --- a/htroot/IndexShare_p.java +++ b/htroot/IndexShare_p.java @@ -39,9 +39,18 @@ public class IndexShare_p { public static serverObjects respond(final httpHeader header, final serverObjects post, final serverSwitch env) { // return variable that accumulates replacements final plasmaSwitchboard switchboard = (plasmaSwitchboard) env; - final serverObjects prop = new serverObjects(); + final serverObjects prop = new serverObjects(); - if ((post == null) || (env == null)) { + if(switchboard == null) { + prop.put("linkfreq", "30"); + prop.put("wordfreq", "10"); + prop.put("dtable", ""); + prop.put("rtable", ""); + prop.putNum("wcount", 0); + prop.putNum("ucount", 0); + return prop; // be save + } + if (post == null) { prop.put("linkfreq", switchboard.getConfig("defaultLinkReceiveFrequency","30")); prop.put("wordfreq", switchboard.getConfig("defaultWordReceiveFrequency","10")); prop.put("dtable", ""); diff --git a/htroot/News.java b/htroot/News.java index cad27b034..ac73fe3ea 100644 --- a/htroot/News.java +++ b/htroot/News.java @@ -27,6 +27,7 @@ import java.io.IOException; import java.util.Iterator; import java.util.Map; +import java.util.Map.Entry; import de.anomic.http.HttpClient; import de.anomic.http.httpHeader; @@ -125,12 +126,9 @@ public class News { prop.putHTML("table_list_" + i + "_att", attributeMap.toString()); int j = 0; if (attributeMap.size() > 0) { - final Iterator attributeKeys = attributeMap.keySet().iterator(); - while (attributeKeys.hasNext()) { - final String key = attributeKeys.next(); - final String value = attributeMap.get(key); - prop.put("table_list_" + i + "_attributes_" + j + "_name",key); - prop.putHTML("table_list_" + i + "_attributes_" + j + "_value",value); + for (Entry attribute: attributeMap.entrySet()) { + prop.put("table_list_" + i + "_attributes_" + j + "_name", attribute.getKey()); + prop.putHTML("table_list_" + i + "_attributes_" + j + "_value", attribute.getValue()); j++; } } diff --git a/htroot/Ranking_p.java b/htroot/Ranking_p.java index feddb7a07..3b271fe5e 100644 --- a/htroot/Ranking_p.java +++ b/htroot/Ranking_p.java @@ -26,8 +26,8 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA import java.util.HashMap; -import java.util.Iterator; import java.util.Map; +import java.util.Map.Entry; import de.anomic.http.httpHeader; import de.anomic.plasma.plasmaSearchEvent; @@ -104,11 +104,10 @@ public class Ranking_p { private static void putRanking(final serverObjects prop, final Map map, final String prefix, final String attrExtension) { prop.put("attr" + attrExtension, map.size()); - final Iterator it = map.keySet().iterator(); String key; int i, j = 0; - while (it.hasNext()) { - key = it.next(); + for (final Entry entry: map.entrySet()) { + key = entry.getKey(); prop.put("attr" + attrExtension + "_" + j + "_name", rankingParameters.get(key.substring(prefix.length()))); prop.put("attr" + attrExtension + "_" + j + "_nameorg", key); prop.put("attr" + attrExtension + "_" + j + "_select", maxRankingRange); @@ -117,7 +116,7 @@ public class Ranking_p { prop.put("attr" + attrExtension + "_" + j + "_select_" + i + "_value", i); try { prop.put("attr" + attrExtension + "_" + j + "_select_" + i + "_checked", - (i == Integer.valueOf(map.get(key)).intValue()) ? "1" : "0"); + (i == Integer.valueOf(entry.getValue()).intValue()) ? "1" : "0"); } catch (final NumberFormatException e) { prop.put("attr" + attrExtension + "_" + j + "_select_" + i + "_checked", "0"); } @@ -135,10 +134,12 @@ public class Ranking_p { plasmaSearchEvent.cleanupEvents(true); // case if no values are requested - if ((post == null) || (env == null)) { + if ((post == null) || (sb == null)) { // we create empty entries for template strings final serverObjects prop = defaultValues(); - final plasmaSearchRankingProfile ranking = sb.getRanking(); + final plasmaSearchRankingProfile ranking; + if(sb == null) ranking = new plasmaSearchRankingProfile(plasmaSearchQuery.CONTENTDOM_TEXT); + else ranking = sb.getRanking(); putRanking(prop, ranking, "local"); return prop; } diff --git a/htroot/Threaddump_p.java b/htroot/Threaddump_p.java index 80dd1e8e4..26bec3b17 100644 --- a/htroot/Threaddump_p.java +++ b/htroot/Threaddump_p.java @@ -33,6 +33,7 @@ import java.io.File; import java.io.IOException; import java.util.Date; import java.util.Map; +import java.util.Map.Entry; import de.anomic.data.htmlTools; import de.anomic.http.httpHeader; @@ -95,8 +96,10 @@ public class Threaddump_p { final File classPath = new File(rootPath, "source"); - for (final Thread thread: stackTraces.keySet()) { - final StackTraceElement[] stackTraceElements = stackTraces.get(thread); + Thread thread; + for (final Entry entry: stackTraces.entrySet()) { + thread = entry.getKey(); + final StackTraceElement[] stackTraceElements = entry.getValue(); StackTraceElement ste; String line; String tracename = ""; diff --git a/htroot/yacy/hello.java b/htroot/yacy/hello.java index cb3a5214c..518425795 100644 --- a/htroot/yacy/hello.java +++ b/htroot/yacy/hello.java @@ -178,7 +178,7 @@ public final class hello { serverCore.checkInterruption(); final StringBuffer seeds = new StringBuffer(768); // attach some more seeds, as requested - if ((sb.webIndex.seedDB != null) && (sb.webIndex.seedDB.sizeConnected() > 0)) { + if (sb.webIndex.seedDB.sizeConnected() > 0) { if (count > sb.webIndex.seedDB.sizeConnected()) { count = sb.webIndex.seedDB.sizeConnected(); } if (count > 100) { count = 100; } diff --git a/source/de/anomic/data/bookmarksDB.java b/source/de/anomic/data/bookmarksDB.java index 705920be0..5850e320d 100644 --- a/source/de/anomic/data/bookmarksDB.java +++ b/source/de/anomic/data/bookmarksDB.java @@ -48,6 +48,7 @@ import java.util.Iterator; import java.util.Map; import java.util.Set; import java.util.TreeSet; +import java.util.Map.Entry; import java.util.regex.Pattern; import javax.xml.parsers.DocumentBuilder; @@ -772,10 +773,9 @@ public class bookmarksDB { writer.close(); links = scraper.getAnchors(); } catch (final IOException e) { serverLog.logWarning("BOOKMARKS", "error during load of links: "+ e.getClass() +" "+ e.getMessage());} - final Iterator it = links.keySet().iterator(); - while (it.hasNext()) { - url= it.next(); - title=links.get(url); + for (Entry link: links.entrySet()) { + url= link.getKey(); + title=link.getValue(); serverLog.logInfo("BOOKMARKS", "links.get(url)"); if(title.equals("")){//cannot be displayed title=url.toString(); diff --git a/source/de/anomic/data/userDB.java b/source/de/anomic/data/userDB.java index f49809376..8724aab75 100644 --- a/source/de/anomic/data/userDB.java +++ b/source/de/anomic/data/userDB.java @@ -432,13 +432,12 @@ public final class userDB { if (timeStamp < 0) throw new IllegalArgumentException(); final Long lastAccess = this.getLastAccess(); - long oldTimeUsed = getTimeUsed(); - long newTimeUsed = oldTimeUsed; + long newTimeUsed = getTimeUsed(); if (incrementTimeUsed) { if ((lastAccess == null)||((lastAccess != null)&&(timeStamp-lastAccess.longValue()>=1000*60))) { //1 minute //this.mem.put(TIME_USED,Long.toString(newTimeUsed = ++oldTimeUsed)); - newTimeUsed = ++oldTimeUsed; + newTimeUsed++; if(lastAccess != null){ this.oldDate.setTime(new Date(lastAccess.longValue())); this.newDate.setTime(new Date(System.currentTimeMillis())); diff --git a/source/de/anomic/http/httpHeader.java b/source/de/anomic/http/httpHeader.java index e65507441..47b2ee9b0 100644 --- a/source/de/anomic/http/httpHeader.java +++ b/source/de/anomic/http/httpHeader.java @@ -343,12 +343,8 @@ public final class httpHeader extends TreeMap implements Map i = keySet().iterator(); - String key, value; - while (i.hasNext()) { - key = i.next(); - value = get(key); - fos.write((key + "=" + value + "\r\n").getBytes()); + for (java.util.Map.Entry entry: entrySet()) { + fos.write((entry.getKey() + "=" + entry.getValue() + "\r\n").getBytes()); } fos.flush(); } finally { diff --git a/source/de/anomic/index/indexDefaultReferenceBlacklist.java b/source/de/anomic/index/indexDefaultReferenceBlacklist.java index bad842090..5bc15bae5 100644 --- a/source/de/anomic/index/indexDefaultReferenceBlacklist.java +++ b/source/de/anomic/index/indexDefaultReferenceBlacklist.java @@ -29,6 +29,7 @@ package de.anomic.index; import java.io.File; import java.util.ArrayList; import java.util.HashMap; +import java.util.Map.Entry; import java.util.regex.Pattern; import java.util.regex.PatternSyntaxException; @@ -99,11 +100,12 @@ public class indexDefaultReferenceBlacklist extends indexAbstractReferenceBlackl // loop over all Regexentrys if(!matched) { final HashMap> blacklistMapNotMatched = super.getBlacklistMap(blacklistType,false); - for(final String key: blacklistMapNotMatched.keySet()) { + String key; + for(final Entry> entry: blacklistMapNotMatched.entrySet()) { + key = entry.getKey(); try { - if(Pattern.matches(key, hostlow)) { - app = blacklistMapNotMatched.get(key); + app = entry.getValue(); for (int i=0; i TreeMap excludeConstructiveByTestMapInSet(final TreeMap map, final TreeSet set) { - final Iterator mi = map.keySet().iterator(); final TreeMap result = new TreeMap(map.comparator()); A o; - while (mi.hasNext()) { - o = mi.next(); - if (!(set.contains(o))) result.put(o, map.get(o)); + for (Entry entry: map.entrySet()) { + o = entry.getKey(); + if (!(set.contains(o))) result.put(o, entry.getValue()); } return result; } diff --git a/source/de/anomic/plasma/plasmaParser.java b/source/de/anomic/plasma/plasmaParser.java index 1775967c5..b3212e0f6 100644 --- a/source/de/anomic/plasma/plasmaParser.java +++ b/source/de/anomic/plasma/plasmaParser.java @@ -48,6 +48,7 @@ import java.util.List; import java.util.Map; import java.util.Properties; import java.util.Set; +import java.util.Map.Entry; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -946,10 +947,9 @@ public final class plasmaParser { // found links int anchorNr = 0; final Map anchors = document.getAnchors(); - final Iterator anchorIter = anchors.keySet().iterator(); - while (anchorIter.hasNext()) { - final yacyURL key = anchorIter.next(); - System.out.println("URL " + anchorNr + ":\t" + key.toString() + " | " + anchors.get(key)); + for (Entry anchor: anchors.entrySet()) { + final yacyURL key = anchor.getKey(); + System.out.println("URL " + anchorNr + ":\t" + key.toString() + " | " + anchor.getValue()); anchorNr++; } document.close(); diff --git a/source/de/anomic/plasma/plasmaSwitchboard.java b/source/de/anomic/plasma/plasmaSwitchboard.java index 6a2f8716d..832069b46 100644 --- a/source/de/anomic/plasma/plasmaSwitchboard.java +++ b/source/de/anomic/plasma/plasmaSwitchboard.java @@ -723,8 +723,10 @@ public final class plasmaSwitchboard extends serverAbstractSwitch 30000) { // we don't want to do this too often updateMySeed(); - serverProfiling.update("ppm", new Long(currentPPM())); + serverProfiling.update("ppm", Long.valueOf(currentPPM())); lastPPMUpdate = System.currentTimeMillis(); } serverProfiling.update("indexed", queueEntry.url().toNormalform(true, false)); @@ -1870,7 +1872,7 @@ public final class plasmaSwitchboard extends serverAbstractSwitch accessSet = tracker.get(host); if (accessSet == null) return 0; - return accessSet.tailSet(new Long(System.currentTimeMillis() - timeInterval)).size(); + return accessSet.tailSet(Long.valueOf(System.currentTimeMillis() - timeInterval)).size(); } public void startTransferWholeIndex(final yacySeed seed, final boolean delete) { @@ -2197,7 +2199,7 @@ public final class plasmaSwitchboard extends serverAbstractSwitch denyHost; int commandMaxLength; private int maxBusySessions; - ConcurrentHashMap busySessions; + final ConcurrentHashMap busySessions; /* private static ServerSocketFactory getServerSocketFactory(boolean dflt, File keyfile, String passphrase) { @@ -400,7 +400,7 @@ public final class serverCore extends serverAbstractBusyThread implements server Thread.interrupted(); // shut down all busySessions - if (this.busySessions != null) for (final Session session: this.busySessions.keySet()) { + for (final Session session: this.busySessions.keySet()) { try { session.interrupt(); } catch (final SecurityException e ) { @@ -420,7 +420,7 @@ public final class serverCore extends serverAbstractBusyThread implements server // close all sessions this.log.logInfo("Closing server sessions ..."); - if (this.busySessions != null) for (final Session s: this.busySessions.keySet()) { + for (final Session s: this.busySessions.keySet()) { s.interrupt(); s.close(); } diff --git a/source/de/anomic/server/serverObjects.java b/source/de/anomic/server/serverObjects.java index 24368b44d..0e7b3f262 100644 --- a/source/de/anomic/server/serverObjects.java +++ b/source/de/anomic/server/serverObjects.java @@ -50,7 +50,6 @@ import java.io.UnsupportedEncodingException; import java.net.InetAddress; import java.util.ArrayList; import java.util.HashMap; -import java.util.Iterator; import java.util.Map; import de.anomic.data.htmlTools; @@ -271,11 +270,10 @@ public class serverObjects extends HashMap implements Cloneable // the keyMapper may contain regular expressions as defined in String.matches // this method is particulary useful when parsing the result of checkbox forms final ArrayList v = new ArrayList(); - final Iterator e = keySet().iterator(); String key; - while (e.hasNext()) { - key = e.next(); - if (key.matches(keyMapper)) v.add(get(key)); + for (Map.Entry entry: entrySet()) { + key = entry.getKey(); + if (key.matches(keyMapper)) v.add(entry.getValue()); } // make a String[] final String[] result = new String[v.size()]; @@ -285,11 +283,8 @@ public class serverObjects extends HashMap implements Cloneable // put all elements of another hashtable into the own table public void putAll(final serverObjects add) { - final Iterator e = add.keySet().iterator(); - String k; - while (e.hasNext()) { - k = e.next(); - put(k, add.get(k)); + for (Map.Entry entry: add.entrySet()) { + put(entry.getKey(), entry.getValue()); } } @@ -298,11 +293,10 @@ public class serverObjects extends HashMap implements Cloneable BufferedOutputStream fos = null; try { fos = new BufferedOutputStream(new FileOutputStream(f)); - final Iterator e = keySet().iterator(); String key, value; - while (e.hasNext()) { - key = e.next(); - value = get(key).replaceAll("\n", "\\\\n"); + for (Map.Entry entry: entrySet()) { + key = entry.getKey(); + value = entry.getValue().replaceAll("\n", "\\\\n"); fos.write((key + "=" + value + "\r\n").getBytes()); } } finally { diff --git a/source/de/anomic/server/serverSystem.java b/source/de/anomic/server/serverSystem.java index e408fc717..b69fa5f84 100644 --- a/source/de/anomic/server/serverSystem.java +++ b/source/de/anomic/server/serverSystem.java @@ -318,7 +318,8 @@ public final class serverSystem { } } catch (final Exception e) { System.err.println("ERROR "+ e.getClass() +" in openBrowser(): "+ e.getMessage()); - System.out.println("please start your browser and open the following location: " + url); + // browser could not be started automatically, tell user to do it + System.out.println("please start your browser and open the following location: " + url); } } diff --git a/source/de/anomic/yacy/yacyPeerActions.java b/source/de/anomic/yacy/yacyPeerActions.java index d258fe385..3f31fca7a 100644 --- a/source/de/anomic/yacy/yacyPeerActions.java +++ b/source/de/anomic/yacy/yacyPeerActions.java @@ -54,7 +54,6 @@ public class yacyPeerActions { if (userAgents != null) userAgents.clear(); userAgents = null; if (dhtAction != null) dhtAction.close(); - dhtAction.close(); } public synchronized boolean connectPeer(final yacySeed seed, final boolean direct) { diff --git a/source/yacy.java b/source/yacy.java index 56183f0ee..45256036a 100644 --- a/source/yacy.java +++ b/source/yacy.java @@ -346,7 +346,7 @@ public final class yacy { final String browserPopUpPage = sb.getConfig("browserPopUpPage", "ConfigBasic.html"); //boolean properPW = (sb.getConfig("adminAccount", "").length() == 0) && (sb.getConfig(httpd.ADMIN_ACCOUNT_B64MD5, "").length() > 0); //if (!properPW) browserPopUpPage = "ConfigBasic.html"; - final String browserPopUpApplication = sb.getConfig("browserPopUpApplication", "netscape"); + final String browserPopUpApplication = sb.getConfig("browserPopUpApplication", "firefox"); serverSystem.openBrowser((server.withSSL()?"https":"http") + "://localhost:" + serverCore.getPortNr(port) + "/" + browserPopUpPage, browserPopUpApplication); }