From 0089f234f4700e0cf726f9265db60658544143e2 Mon Sep 17 00:00:00 2001 From: Michael Peter Christen Date: Fri, 1 Sep 2023 12:18:47 +0200 Subject: [PATCH] added npe protection --- source/net/yacy/kelondro/util/SetTools.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/source/net/yacy/kelondro/util/SetTools.java b/source/net/yacy/kelondro/util/SetTools.java index 96a38445a..450e9cd61 100644 --- a/source/net/yacy/kelondro/util/SetTools.java +++ b/source/net/yacy/kelondro/util/SetTools.java @@ -169,10 +169,10 @@ public final class SetTools { @SuppressWarnings("unchecked") private static SortedMap joinConstructiveByEnumeration(final SortedMap map1, final SortedMap map2, final boolean concatStrings) { // implement pairwise enumeration - final Comparator comp = map1.comparator(); + final Comparator comp = map1.comparator() == null ? (Comparator) Comparator.naturalOrder() : map1.comparator(); final Iterator> mi1 = map1.entrySet().iterator(); final Iterator> mi2 = map2.entrySet().iterator(); - final SortedMap result = new TreeMap(map1.comparator()); + final SortedMap result = new TreeMap(comp); int c; if ((mi1.hasNext()) && (mi2.hasNext())) { Map.Entry mentry1 = mi1.next(); @@ -263,6 +263,8 @@ public final class SetTools { * @return true if the small set is completely included in the large set */ public static boolean totalInclusion(final Iterator small, final Set large) { + if (small == null) return true; + if (large == null) return false; while (small.hasNext()) { if (!large.contains(small.next())) return false; } @@ -276,6 +278,8 @@ public final class SetTools { * @return true if the small set is completely included in the large set */ public static boolean totalInclusion(final HandleSet small, final HandleSet large) { + if (small == null) return true; + if (large == null) return false; for (byte[] handle: small) { if (!large.has(handle)) return false; }