Skip to content

Commit 6f6b79b

Browse files
author
Vladimir Kotal
authored
Suggester Sonar fixes (#3806)
* check await() return value * add missing javadoc param comment * avoid concatenation * avoid string concatenation * fix javadoc warning * address review comments
1 parent ad1826b commit 6f6b79b

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

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

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public final class Suggester implements Closeable {
121121
* @param allowedFields fields for which should the suggester be enabled,
122122
* if {@code null} then enabled for all fields
123123
* @param timeThreshold time in milliseconds after which the suggestions requests should time out
124-
* @param registry
124+
* @param registry meter registry
125125
*/
126126
public Suggester(
127127
final File suggesterDir,
@@ -196,10 +196,12 @@ public void init(final Collection<NamedIndexDir> luceneIndexes) {
196196
* wait for initialization to finish.
197197
* @param timeout timeout value
198198
* @param unit timeout unit
199-
* @throws InterruptedException
199+
* @throws InterruptedException on canceled await()
200200
*/
201201
public void waitForInit(long timeout, TimeUnit unit) throws InterruptedException {
202-
initDone.await(timeout, unit);
202+
if (!initDone.await(timeout, unit)) {
203+
LOGGER.log(Level.WARNING, "Initialization did not finish in {0} {1}", new Object[] {timeout, unit});
204+
}
203205
}
204206

205207
private void submitInitIfIndexExists(final ExecutorService executorService, final NamedIndexDir indexDir) {
@@ -236,7 +238,7 @@ private Runnable getInitRunnable(final NamedIndexDir indexDir) {
236238
Duration d = Duration.between(start, Instant.now());
237239
LOGGER.log(Level.FINE, "Finished initialization of {0}, took {1}", new Object[] {indexDir, d});
238240
} catch (Exception e) {
239-
LOGGER.log(Level.SEVERE, "Could not initialize suggester data for " + indexDir, e);
241+
LOGGER.log(Level.SEVERE, String.format("Could not initialize suggester data for %s", indexDir), e);
240242
}
241243
};
242244
}
@@ -322,13 +324,15 @@ public void rebuild(final Collection<NamedIndexDir> indexDirs) {
322324
* wait for rebuild to finish.
323325
* @param timeout timeout value
324326
* @param unit timeout unit
325-
* @throws InterruptedException
327+
* @throws InterruptedException on canceled await()
326328
*/
327329
public void waitForRebuild(long timeout, TimeUnit unit) throws InterruptedException {
328330
rebuildLock.lock();
329331
try {
330332
while (rebuilding) {
331-
rebuildDone.await(timeout, unit);
333+
if (!rebuildDone.await(timeout, unit)) {
334+
LOGGER.log(Level.WARNING, "Rebuild did not finish in {0} {1}", new Object[] {timeout, unit});
335+
}
332336
}
333337
} finally {
334338
rebuildLock.unlock();
@@ -610,7 +614,7 @@ public void close() {
610614
try {
611615
f.close();
612616
} catch (IOException e) {
613-
LOGGER.log(Level.WARNING, "Could not close suggester data " + f, e);
617+
LOGGER.log(Level.WARNING, String.format("Could not close suggester data %s", f), e);
614618
}
615619
});
616620
}

0 commit comments

Comments
 (0)