Skip to content

Commit 333435f

Browse files
author
Vladimir Kotal
committed
skip search count map init if number entries is 0
1 parent b71b247 commit 333435f

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

suggester/src/main/java/org/opengrok/suggest/SuggesterProjectData.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -289,9 +289,16 @@ private void initSearchCountMap() throws IOException {
289289
searchCountMaps.clear();
290290

291291
for (String field : fields) {
292+
int numEntries = (int) lookups.get(field).getCount();
293+
if (numEntries == 0) {
294+
logger.log(Level.FINE, "Skipping creation of ChronicleMap for field " + field + " in directory "
295+
+ suggesterDir + " due to zero number of entries");
296+
continue;
297+
}
298+
292299
ChronicleMapConfiguration conf = ChronicleMapConfiguration.load(suggesterDir, field);
293300
if (conf == null) { // it was not yet initialized
294-
conf = new ChronicleMapConfiguration((int) lookups.get(field).getCount(), getAverageLength(field));
301+
conf = new ChronicleMapConfiguration(numEntries, getAverageLength(field));
295302
conf.save(suggesterDir, field);
296303
}
297304

@@ -301,12 +308,14 @@ private void initSearchCountMap() throws IOException {
301308
try {
302309
m = new ChronicleMapAdapter(field, conf.getAverageKeySize(), conf.getEntries(), f);
303310
} catch (IllegalArgumentException e) {
304-
logger.log(Level.SEVERE, "Could not create ChronicleMap due to invalid key size: "
305-
+ conf.getAverageKeySize(), e);
311+
logger.log(Level.SEVERE, "Could not create ChronicleMap for field " + field + " in directory "
312+
+ suggesterDir + " due to invalid key size ("
313+
+ conf.getAverageKeySize() + ") or number of entries: (" + conf.getEntries() + "):", e);
306314
return;
307315
} catch (Throwable t) {
308316
logger.log(Level.SEVERE,
309-
"Could not create ChronicleMap, most popular completion disabled, if you are using "
317+
"Could not create ChronicleMap for field " + field + " in directory "
318+
+ suggesterDir + " , most popular completion disabled, if you are using "
310319
+ "JDK9+ make sure to specify: "
311320
+ "--add-exports java.base/jdk.internal.ref=ALL-UNNAMED "
312321
+ "--add-exports java.base/jdk.internal.misc=ALL-UNNAMED "

0 commit comments

Comments
 (0)