lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a.@apache.org
Subject [lucene-solr] branch jira/solr-14914 updated: SOLR-14914: Avoid NPE when loader is null but info isn't.
Date Wed, 14 Oct 2020 15:44:35 GMT
This is an automated email from the ASF dual-hosted git repository.

ab pushed a commit to branch jira/solr-14914
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git


The following commit(s) were added to refs/heads/jira/solr-14914 by this push:
     new f7f7878  SOLR-14914: Avoid NPE when loader is null but info isn't.
f7f7878 is described below

commit f7f78785ed95e5ef6a0189e71a469517e141037e
Author: Andrzej Bialecki <ab@apache.org>
AuthorDate: Wed Oct 14 17:44:02 2020 +0200

    SOLR-14914: Avoid NPE when loader is null but info isn't.
---
 .../org/apache/solr/metrics/MetricSuppliers.java   | 76 ++++++++++++++--------
 1 file changed, 48 insertions(+), 28 deletions(-)

diff --git a/solr/core/src/java/org/apache/solr/metrics/MetricSuppliers.java b/solr/core/src/java/org/apache/solr/metrics/MetricSuppliers.java
index 5d0f294..a53fa4c 100644
--- a/solr/core/src/java/org/apache/solr/metrics/MetricSuppliers.java
+++ b/solr/core/src/java/org/apache/solr/metrics/MetricSuppliers.java
@@ -191,17 +191,21 @@ public class MetricSuppliers {
       return new SlidingWindowReservoir(size);
     } else { // custom reservoir
       Reservoir reservoir;
-      try {
-        reservoir = loader.newInstance(clazz, Reservoir.class);
-        if (reservoir instanceof PluginInfoInitialized) {
-          ((PluginInfoInitialized)reservoir).init(info);
-        } else {
-          SolrPluginUtils.invokeSetters(reservoir, info.initArgs, true);
-        }
-        return reservoir;
-      } catch (Exception e) {
-        log.warn("Error initializing custom Reservoir implementation (will use default):
{}", info, e);
+      if (loader == null) {
         return new ExponentiallyDecayingReservoir(size, alpha, clk);
+      } else {
+        try {
+          reservoir = loader.newInstance(clazz, Reservoir.class);
+          if (reservoir instanceof PluginInfoInitialized) {
+            ((PluginInfoInitialized)reservoir).init(info);
+          } else {
+            SolrPluginUtils.invokeSetters(reservoir, info.initArgs, true);
+          }
+          return reservoir;
+        } catch (Exception e) {
+          log.warn("Error initializing custom Reservoir implementation (will use default):
{}", info, e);
+          return new ExponentiallyDecayingReservoir(size, alpha, clk);
+        }
       }
     }
   }
@@ -280,11 +284,15 @@ public class MetricSuppliers {
       return NoOpCounterSupplier.INSTANCE;
     }
     MetricRegistry.MetricSupplier<Counter> supplier;
-    try {
-      supplier = loader.newInstance(info.className, MetricRegistry.MetricSupplier.class);
-    } catch (Exception e) {
-      log.warn("Error creating custom Counter supplier (will use default): {}", info, e);
+    if (loader == null) {
       supplier = new DefaultCounterSupplier();
+    } else {
+      try {
+        supplier = loader.newInstance(info.className, MetricRegistry.MetricSupplier.class);
+      } catch (Exception e) {
+        log.warn("Error creating custom Counter supplier (will use default): {}", info, e);
+        supplier = new DefaultCounterSupplier();
+      }
     }
     if (supplier instanceof PluginInfoInitialized) {
       ((PluginInfoInitialized)supplier).init(info);
@@ -309,11 +317,15 @@ public class MetricSuppliers {
       if (MetricsConfig.NOOP_IMPL_CLASS.equals(info.className)) {
         return NoOpMeterSupplier.INSTANCE;
       }
-      try {
-        supplier = loader.newInstance(info.className, MetricRegistry.MetricSupplier.class);
-      } catch (Exception e) {
-        log.warn("Error creating custom Meter supplier (will use default): {}",info, e);
+      if (loader == null) {
         supplier = new DefaultMeterSupplier();
+      } else {
+        try {
+          supplier = loader.newInstance(info.className, MetricRegistry.MetricSupplier.class);
+        } catch (Exception e) {
+          log.warn("Error creating custom Meter supplier (will use default): {}",info, e);
+          supplier = new DefaultMeterSupplier();
+        }
       }
     }
     if (supplier instanceof PluginInfoInitialized) {
@@ -339,11 +351,15 @@ public class MetricSuppliers {
       if (MetricsConfig.NOOP_IMPL_CLASS.equals(info.className)) {
         return NoOpTimerSupplier.INSTANCE;
       }
-      try {
-        supplier = loader.newInstance(info.className, MetricRegistry.MetricSupplier.class);
-      } catch (Exception e) {
-        log.warn("Error creating custom Timer supplier (will use default): {}", info, e);
-        supplier = new DefaultTimerSupplier(loader);
+      if (loader == null) {
+        supplier = new DefaultTimerSupplier(null);
+      } else {
+        try {
+          supplier = loader.newInstance(info.className, MetricRegistry.MetricSupplier.class);
+        } catch (Exception e) {
+          log.warn("Error creating custom Timer supplier (will use default): {}", info, e);
+          supplier = new DefaultTimerSupplier(loader);
+        }
       }
     }
     if (supplier instanceof PluginInfoInitialized) {
@@ -368,11 +384,15 @@ public class MetricSuppliers {
       if (MetricsConfig.NOOP_IMPL_CLASS.equals(info.className)) {
         return NoOpHistogramSupplier.INSTANCE;
       }
-      try {
-        supplier = loader.newInstance(info.className, MetricRegistry.MetricSupplier.class);
-      } catch (Exception e) {
-        log.warn("Error creating custom Histogram supplier (will use default): {}", info,
e);
-        supplier = new DefaultHistogramSupplier(loader);
+      if (loader == null) {
+        supplier = new DefaultHistogramSupplier(null);
+      } else {
+        try {
+          supplier = loader.newInstance(info.className, MetricRegistry.MetricSupplier.class);
+        } catch (Exception e) {
+          log.warn("Error creating custom Histogram supplier (will use default): {}", info,
e);
+          supplier = new DefaultHistogramSupplier(loader);
+        }
       }
     }
     if (supplier instanceof PluginInfoInitialized) {


Mime
View raw message