Skip to content

Commit 2e0c91f

Browse files
authored
Avoid NPE when level is not set for stats logger. (#60)
Avoid NPE when stats logger doesn't have a level set.
1 parent d0190b2 commit 2e0c91f

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

driver/src/main/java/oracle/nosql/driver/http/Stats.java

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -434,16 +434,18 @@ synchronized void clear() {
434434
extraQueryStats = new ExtraQueryStats(statsControl);
435435
}
436436

437-
// Setup the scheduler for interval logging
437+
// Set up the scheduler for interval logging
438438
Runnable runnable = () -> {
439439
try {
440440
logClientStats();
441441
} catch (RuntimeException re) {
442-
StringWriter stackTrace = new StringWriter();
443-
re.printStackTrace(new PrintWriter(stackTrace));
444-
statsControl.getLogger().log(Level.INFO,
445-
"Stats exception: " + re.getMessage() + "\n" +
446-
stackTrace);
442+
if (statsControl.getLogger() != null) {
443+
StringWriter stackTrace = new StringWriter();
444+
re.printStackTrace(new PrintWriter(stackTrace));
445+
statsControl.getLogger().log(Level.INFO,
446+
"Stats exception: " + re.getMessage() + "\n" +
447+
stackTrace);
448+
}
447449
}
448450
};
449451

@@ -482,10 +484,12 @@ private void logClientStats() {
482484
}
483485

484486
// Output stats to logger.
485-
String json = fvStats.toJson(statsControl.getPrettyPrint() ?
486-
JsonOptions.PRETTY : null);
487-
statsControl.getLogger().log(Level.INFO,
488-
StatsControl.LOG_PREFIX + json);
487+
if (statsControl.getLogger() != null) {
488+
String json = fvStats.toJson(statsControl.getPrettyPrint() ?
489+
JsonOptions.PRETTY : null);
490+
statsControl.getLogger().log(Level.INFO,
491+
StatsControl.LOG_PREFIX + json);
492+
}
489493
}
490494

491495
private MapValue generateFieldValueStats() {

driver/src/main/java/oracle/nosql/driver/http/StatsControlImpl.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ public class StatsControlImpl
4343

4444
if (profile != Profile.NONE) {
4545
if (config.getStatsEnableLog() &&
46-
logger.getLevel().intValue() > Level.INFO.intValue()) {
46+
( logger.getLevel() == null ||
47+
logger.getLevel().intValue() > Level.INFO.intValue())) {
4748
logger.setLevel(Level.INFO);
4849
}
4950
logger.log(Level.INFO, LOG_PREFIX +

0 commit comments

Comments
 (0)