Skip to content

Commit 9c72bc5

Browse files
committed
do not log stack trace for CacheException reporting disabled cache annotation
fixes #4596
1 parent fd87436 commit 9c72bc5

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

opengrok-indexer/src/main/java/org/opengrok/indexer/history/CacheException.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919

2020
/*
21-
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
21+
* Copyright (c) 2022, 2024, Oracle and/or its affiliates. All rights reserved.
2222
*/
2323
package org.opengrok.indexer.history;
2424

@@ -32,6 +32,7 @@ public class CacheException extends Exception {
3232
private static final long serialVersionUID = 1L;
3333

3434
private final Level level;
35+
private final boolean logTrace;
3536

3637
/**
3738
* Construct a {@code CacheException} with the specified message.
@@ -50,6 +51,20 @@ public CacheException(String msg) {
5051
public CacheException(String msg, Level level) {
5152
super(msg);
5253
this.level = level;
54+
this.logTrace = true;
55+
}
56+
57+
/**
58+
* Construct a {@code CacheException} with the specified message and log level
59+
* and whether to log stack trace.
60+
* @param msg message
61+
* @param level suggested log level
62+
* @param logTrace whether to log stack trace
63+
*/
64+
public CacheException(String msg, Level level, boolean logTrace) {
65+
super(msg);
66+
this.level = level;
67+
this.logTrace = logTrace;
5368
}
5469

5570
/**
@@ -60,6 +75,7 @@ public CacheException(String msg, Level level) {
6075
public CacheException(Throwable cause) {
6176
super(cause);
6277
this.level = Level.WARNING;
78+
this.logTrace = true;
6379
}
6480

6581
/**
@@ -71,6 +87,7 @@ public CacheException(Throwable cause) {
7187
public CacheException(String msg, Throwable cause) {
7288
super(msg, cause);
7389
this.level = Level.WARNING;
90+
this.logTrace = true;
7491
}
7592

7693
/**
@@ -79,4 +96,8 @@ public CacheException(String msg, Throwable cause) {
7996
public Level getLevel() {
8097
return level;
8198
}
99+
100+
public boolean isLogTrace() {
101+
return this.logTrace;
102+
}
82103
}

opengrok-indexer/src/main/java/org/opengrok/indexer/history/HistoryGuru.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1180,7 +1180,7 @@ public void createAnnotationCache(File file, String latestRev) throws CacheExcep
11801180
if (!repository.isWorking() || !repository.isAnnotationCacheEnabled()) {
11811181
throw new CacheException(
11821182
String.format("repository %s does not allow to create annotation cache for '%s'",
1183-
repository, file), Level.FINER);
1183+
repository, file), Level.FINER, false);
11841184
}
11851185

11861186
LOGGER.finest(() -> String.format("creating annotation cache for '%s'", launderLog(file.toString())));

opengrok-indexer/src/main/java/org/opengrok/indexer/index/IndexDatabase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1306,7 +1306,7 @@ private static void createAnnotationCache(File file, Document doc) {
13061306
// call above) directly.
13071307
HistoryGuru.getInstance().createAnnotationCache(file, lastRev);
13081308
} catch (CacheException e) {
1309-
LOGGER.log(e.getLevel(), "failed to create annotation", e);
1309+
LOGGER.log(e.getLevel(), "failed to create annotation", e.isLogTrace() ? e : e.getMessage());
13101310
}
13111311
}
13121312
}

0 commit comments

Comments
 (0)