You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@zookeeper.apache.org by "LiAoNan (Jira)" <ji...@apache.org> on 2020/12/23 05:49:00 UTC

[jira] [Created] (ZOOKEEPER-4033) Remove unnecessary judgment of null

LiAoNan created ZOOKEEPER-4033:
----------------------------------

             Summary: Remove unnecessary judgment of null
                 Key: ZOOKEEPER-4033
                 URL: https://issues.apache.org/jira/browse/ZOOKEEPER-4033
             Project: ZooKeeper
          Issue Type: Improvement
            Reporter: LiAoNan


in the method of `QuorumPeerMain.runFromConfig`
{code:java}
        try {
            metricsProvider = MetricsProviderBootstrap.startMetricsProvider(
                config.getMetricsProviderClassName(),
                config.getMetricsProviderConfiguration());
        } catch (MetricsProviderLifeCycleException error) {
            throw new IOException("Cannot boot MetricsProvider " + config.getMetricsProviderClassName(), error);
        }
{code}
causing exception or metricsProvider will never be null
{code:java}
        try {
             ...
        } finally {
            if (metricsProvider != null) {
                try {
                    metricsProvider.stop();
                } catch (Throwable error) {
                    LOG.warn("Error while stopping metrics", error);
                }
            }
        }
{code}
So there's no need to check again in the finally code block.
 remove it
{code:java}
finally {
            try {
                metricsProvider.stop();
            } catch (Throwable error) {
                LOG.warn("Error while stopping metrics", error);
            }
        }
{code}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)