This is an automated email from the ASF dual-hosted git repository.

kimmking pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new 7262238  Fixes NPE when proxy starts without cluster or metrics 
configuration (#6133)
7262238 is described below

commit 72622387bf0a9ae4e5ea3cbde76f0dedf922697d
Author: Haoran Meng <loca...@163.com>
AuthorDate: Fri Jun 19 16:31:47 2020 +0800

    Fixes NPE when proxy starts without cluster or metrics configuration (#6133)
---
 .../shardingsphere/metrics/facade/MetricsTrackerFacade.java |  1 +
 .../java/org/apache/shardingsphere/proxy/Bootstrap.java     | 13 +++++++++++--
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git 
a/shardingsphere-control-panel/shardingsphere-metrics/shardingsphere-metrics-facade/src/main/java/org/apache/shardingsphere/metrics/facade/MetricsTrackerFacade.java
 
b/shardingsphere-control-panel/shardingsphere-metrics/shardingsphere-metrics-facade/src/main/java/org/apache/shardingsphere/metrics/facade/MetricsTrackerFacade.java
index 34936a4..83ba58e 100644
--- 
a/shardingsphere-control-panel/shardingsphere-metrics/shardingsphere-metrics-facade/src/main/java/org/apache/shardingsphere/metrics/facade/MetricsTrackerFacade.java
+++ 
b/shardingsphere-control-panel/shardingsphere-metrics/shardingsphere-metrics-facade/src/main/java/org/apache/shardingsphere/metrics/facade/MetricsTrackerFacade.java
@@ -74,6 +74,7 @@ public final class MetricsTrackerFacade {
      * @param metricsConfiguration metrics configuration
      */
     public void init(final MetricsConfiguration metricsConfiguration) {
+        Preconditions.checkNotNull(metricsConfiguration, "metrics 
configuration can not be null.");
         metricsTrackerManager = 
findMetricsTrackerManager(metricsConfiguration.getMetricsName());
         Preconditions.checkNotNull(metricsTrackerManager, "Can not find 
metrics tracker manager with metrics name in metrics configuration.");
         metricsTrackerManager.start(metricsConfiguration);
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/Bootstrap.java
 
b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/Bootstrap.java
index f97d04a..7e70d5b 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/Bootstrap.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/Bootstrap.java
@@ -66,6 +66,7 @@ import java.util.Collection;
 import java.util.LinkedHashMap;
 import java.util.Map;
 import java.util.Map.Entry;
+import java.util.Optional;
 import java.util.Properties;
 import java.util.stream.Collectors;
 
@@ -125,8 +126,8 @@ public final class Bootstrap {
         Authentication authentication = new 
AuthenticationYamlSwapper().swapToObject(yamlAuthenticationConfig);
         Map<String, Map<String, DataSourceParameter>> schemaDataSources = 
getDataSourceParametersMap(ruleConfigs);
         Map<String, Collection<RuleConfiguration>> schemaRules = 
getRuleConfigurations(ruleConfigs);
-        initialize(authentication, properties, schemaDataSources, schemaRules, 
new MetricsConfigurationYamlSwapper().swapToObject(metricsConfiguration),
-                new 
ClusterConfigurationYamlSwapper().swapToObject(clusterConfiguration), false);
+        initialize(authentication, properties, schemaDataSources, schemaRules, 
getMetricsConfiguration(metricsConfiguration),
+                getClusterConfiguration(clusterConfiguration), false);
         ShardingSphereProxy.getInstance().start(port);
     }
     
@@ -280,6 +281,14 @@ public final class Bootstrap {
         return result;
     }
     
+    private static MetricsConfiguration getMetricsConfiguration(final 
YamlMetricsConfiguration yamlMetricsConfiguration) {
+        return Optional.ofNullable(yamlMetricsConfiguration).map(new 
MetricsConfigurationYamlSwapper()::swapToObject).orElse(null);
+    }
+    
+    private static ClusterConfiguration getClusterConfiguration(final 
YamlClusterConfiguration yamlClusterConfiguration) {
+        return Optional.ofNullable(yamlClusterConfiguration).map(new 
ClusterConfigurationYamlSwapper()::swapToObject).orElse(null);
+    }
+    
     /**
      * Log rule configurations.
      *

Reply via email to