From 9d84f7bece9f0c61453f3e52aee3721fb7d80646 Mon Sep 17 00:00:00 2001 From: Mero Rai Date: Wed, 24 Feb 2021 11:11:43 +0000 Subject: [PATCH] Merge pull request #306 from MeroRai/FISH-1084 FISH-1084 NullPointerException when getting monitoring data for JDBC --- .../sun/gjc/monitoring/JdbcStatsProvider.java | 33 +++++++++++-------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/appserver/jdbc/jdbc-ra/jdbc-core/src/main/java/com/sun/gjc/monitoring/JdbcStatsProvider.java b/appserver/jdbc/jdbc-ra/jdbc-core/src/main/java/com/sun/gjc/monitoring/JdbcStatsProvider.java index ceed06a74ae..8ec3004df88 100644 --- a/appserver/jdbc/jdbc-ra/jdbc-core/src/main/java/com/sun/gjc/monitoring/JdbcStatsProvider.java +++ b/appserver/jdbc/jdbc-ra/jdbc-core/src/main/java/com/sun/gjc/monitoring/JdbcStatsProvider.java @@ -209,15 +209,17 @@ public CountStatistic getNumStatementCacheMiss() { @ManagedAttribute(id="frequsedsqlqueries") public ListStatistic getfreqUsedSqlQueries() { - List sqlTraces = freqSqlTraceCache.getTopQueries(); - freqUsedSqlQueries = new ListStatisticImpl("frequsedsqlqueries", "List", "Most frequently used sql queries"); - - for (SQLTrace trace : sqlTraces){ - CountStatisticImpl stat = new CountStatisticImpl(trace.getQueryName(), "Count", ""); - stat.setCount(trace.getNumExecutions()); - freqUsedSqlQueries.add(stat); + if (freqSqlTraceCache != null) { + List sqlTraces = freqSqlTraceCache.getTopQueries(); + freqUsedSqlQueries = new ListStatisticImpl("frequsedsqlqueries", "List", "Most frequently used sql queries"); + + for (SQLTrace trace : sqlTraces) { + CountStatisticImpl stat = new CountStatisticImpl(trace.getQueryName(), "Count", ""); + stat.setCount(trace.getNumExecutions()); + freqUsedSqlQueries.add(stat); + } } - + return freqUsedSqlQueries; } @@ -226,12 +228,15 @@ public ListStatistic getSlowSqlQueries() { //Make sure no data from previous execution is kept slowSqlQueries.reset(); slowSqlQueries.clear(); - //Get slow queries and process them - List slowTraces = slowSqlTraceCache.getSlowestSqlQueries(); - for (SlowSqlTrace trace: slowTraces){ - CountStatisticImpl stat = new CountStatisticImpl(trace.getQueryName(), StatisticImpl.UNIT_MILLISECOND, "Longest execution time"); - stat.setCount(trace.getSlowestExecutionTime()); - slowSqlQueries.add(stat); + + if (slowSqlTraceCache != null) { + //Get slow queries and process them + List slowTraces = slowSqlTraceCache.getSlowestSqlQueries(); + for (SlowSqlTrace trace : slowTraces) { + CountStatisticImpl stat = new CountStatisticImpl(trace.getQueryName(), StatisticImpl.UNIT_MILLISECOND, "Longest execution time"); + stat.setCount(trace.getSlowestExecutionTime()); + slowSqlQueries.add(stat); + } } return slowSqlQueries;