You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by ki...@apache.org on 2020/06/24 08:14:33 UTC

[shardingsphere] branch master updated: Fixes npe when proxy start without metrics (#6182)

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 e9cc082  Fixes npe when proxy start without metrics (#6182)
e9cc082 is described below

commit e9cc08271ed7dec282a89a33b9b6f934b11d7ede
Author: Haoran Meng <lo...@163.com>
AuthorDate: Wed Jun 24 16:14:16 2020 +0800

    Fixes npe when proxy start without metrics (#6182)
---
 .../shardingsphere/orchestration/core/configcenter/ConfigCenter.java | 3 ++-
 .../src/main/java/org/apache/shardingsphere/proxy/Bootstrap.java     | 5 ++---
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-configcenter/src/main/java/org/apache/shardingsphere/orchestration/core/configcenter/ConfigCenter.java b/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-configcenter/src/main/java/org/apache/shardingsphere/orchestration/core/configcenter/ConfigCenter.java
index e16c9c1..c239d68 100644
--- a/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-configcenter/src/main/java/org/apache/shardingsphere/orchestration/core/configcenter/ConfigCenter.java
+++ b/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-configcenter/src/main/java/org/apache/shardingsphere/orchestration/core/configcenter/ConfigCenter.java
@@ -272,7 +272,8 @@ public final class ConfigCenter {
      * @return metrics configuration
      */
     public MetricsConfiguration loadMetricsConfiguration() {
-        return new MetricsConfigurationYamlSwapper().swapToObject(YamlEngine.unmarshal(repository.get(node.getMetricsPath()), YamlMetricsConfiguration.class));
+        return Strings.isNullOrEmpty(repository.get(node.getMetricsPath())) ? null
+            : new MetricsConfigurationYamlSwapper().swapToObject(YamlEngine.unmarshal(repository.get(node.getMetricsPath()), YamlMetricsConfiguration.class));
     }
     
     /**
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 c727ab2..49c24ac 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
@@ -235,9 +235,8 @@ public final class Bootstrap {
             shardingOrchestrationFacade.init(getDataSourceConfigurationMap(ruleConfigs),
                     getRuleConfigurations(ruleConfigs), new AuthenticationYamlSwapper().swapToObject(serverConfig.getAuthentication()), serverConfig.getProps());
         }
-        shardingOrchestrationFacade.initMetricsConfiguration(new MetricsConfigurationYamlSwapper().swapToObject(serverConfig.getMetrics()));
-        shardingOrchestrationFacade.initClusterConfiguration(null == serverConfig.getCluster() ? null
-                : new ClusterConfigurationYamlSwapper().swapToObject(serverConfig.getCluster()));
+        shardingOrchestrationFacade.initMetricsConfiguration(Optional.ofNullable(serverConfig.getMetrics()).map(new MetricsConfigurationYamlSwapper()::swapToObject).orElse(null));
+        shardingOrchestrationFacade.initClusterConfiguration(Optional.ofNullable(serverConfig.getCluster()).map(new ClusterConfigurationYamlSwapper()::swapToObject).orElse(null));
     }
     
     private static void initOpenTracing() {