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

crazyhzm pushed a commit to branch 3.0
in repository https://gitbox.apache.org/repos/asf/dubbo.git


The following commit(s) were added to refs/heads/3.0 by this push:
     new e34797c  Code optimization and fix typo (#9840)
e34797c is described below

commit e34797ce3bbae90887f5a04f82c3cfe7ebd99194
Author: 灼华 <[email protected]>
AuthorDate: Mon Mar 28 11:46:27 2022 +0800

    Code optimization and fix typo (#9840)
    
    * Code Adjust
    
    * Fix typo
    
    * FIX UT
    
    * FIX UT
    
    * Adjust the order of the two if judgments
---
 .../java/org/apache/dubbo/rpc/cluster/ClusterInvoker.java     |  2 +-
 .../router/condition/config/model/ConditionRouterRule.java    |  3 ---
 .../dubbo/rpc/cluster/router/file/FileStateRouterFactory.java |  3 +--
 .../org/apache/dubbo/rpc/cluster/router/tag/model/Tag.java    |  3 ---
 .../dubbo/rpc/cluster/support/AvailableClusterInvoker.java    |  2 +-
 .../dubbo/rpc/cluster/support/BroadcastClusterInvoker.java    | 11 ++++++++---
 .../rpc/cluster/support/registry/ZoneAwareClusterInvoker.java |  2 +-
 .../dubbo/rpc/cluster/support/wrapper/MockClusterInvoker.java | 10 +++++-----
 ...ConditionRouterTest.java => ConditionStateRouterTest.java} |  2 +-
 .../mesh/rule/virtualservice/match/DubboMethodMatchTest.java  |  3 ---
 .../dubbo/rpc/cluster/router/tag/TagStateRouterTest.java      |  2 --
 .../rpc/cluster/support/wrapper/MockClusterInvokerTest.java   |  6 +++---
 .../java/org/apache/dubbo/common/BaseServiceMetadata.java     |  4 ++--
 .../main/java/org/apache/dubbo/common/config/Environment.java |  2 +-
 .../org/apache/dubbo/common/config/ModuleEnvironment.java     |  7 ++++++-
 .../org/apache/dubbo/common/extension/ExtensionDirector.java  |  2 ++
 .../main/java/org/apache/dubbo/rpc/model/ConsumerModel.java   |  2 +-
 .../src/main/java/org/apache/dubbo/rpc/model/ModuleModel.java |  5 +++++
 .../main/java/org/apache/dubbo/rpc/model/ProviderModel.java   |  3 +--
 .../main/java/org/apache/dubbo/rpc/model/ServiceMetadata.java |  3 +--
 .../annotation/ReferenceAnnotationBeanPostProcessor.java      |  6 +++---
 .../factory/annotation/ServiceAnnotationPostProcessor.java    |  2 +-
 .../DubboConfigDefaultPropertyValueBeanPostProcessor.java     |  2 +-
 .../config/spring/context/DubboConfigApplicationListener.java |  2 +-
 .../dubbo/config/spring/context/DubboSpringInitializer.java   |  2 +-
 .../dubbo/config/spring/reference/ReferenceBeanSupport.java   |  2 +-
 .../apache/dubbo/config/spring/util/DubboAnnotationUtils.java |  5 ++---
 .../org/apache/dubbo/config/spring/util/DubboBeanUtils.java   |  2 +-
 .../beans/factory/annotation/MethodConfigCallbackTest.java    |  4 ++--
 .../beans/factory/annotation/ServiceBeanNameBuilderTest.java  |  3 ---
 .../org/apache/dubbo/metadata/AbstractServiceNameMapping.java |  1 +
 .../dubbo/registry/client/AbstractServiceDiscovery.java       |  3 +++
 .../dubbo/registry/client/ServiceDiscoveryRegistryTest.java   |  1 -
 33 files changed, 57 insertions(+), 55 deletions(-)

diff --git 
a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/ClusterInvoker.java 
b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/ClusterInvoker.java
index 32187e6..0128086 100644
--- 
a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/ClusterInvoker.java
+++ 
b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/ClusterInvoker.java
@@ -25,7 +25,7 @@ import org.apache.dubbo.rpc.Invoker;
  * A ClusterInvoker holds a group of normal invokers, stored in a Directory, 
mapping to one Registry.
  * The ClusterInvoker implementation usually provides LB or HA policies, like 
FailoverClusterInvoker.
  * <p>
- * In multi-registry subscription scenario, the final ClusterInvoker will 
referr to several sub ClusterInvokers, with each
+ * In multi-registry subscription scenario, the final ClusterInvoker will 
refer to several sub ClusterInvokers, with each
  * sub ClusterInvoker representing one Registry. Take ZoneAwareClusterInvoker 
as an example, it is specially customized for
  * multi-registry use cases: first, pick up one ClusterInvoker, then do LB 
inside the chose ClusterInvoker.
  *
diff --git 
a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/condition/config/model/ConditionRouterRule.java
 
b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/condition/config/model/ConditionRouterRule.java
index 0b2aa42..0cfb8bd 100644
--- 
a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/condition/config/model/ConditionRouterRule.java
+++ 
b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/condition/config/model/ConditionRouterRule.java
@@ -24,9 +24,6 @@ import java.util.stream.Collectors;
 
 import static org.apache.dubbo.rpc.cluster.Constants.CONDITIONS_KEY;
 
-/**
- *
- */
 public class ConditionRouterRule extends AbstractRouterRule {
     private List<String> conditions;
 
diff --git 
a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/file/FileStateRouterFactory.java
 
b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/file/FileStateRouterFactory.java
index 9bdd5ca..5e037a9 100644
--- 
a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/file/FileStateRouterFactory.java
+++ 
b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/file/FileStateRouterFactory.java
@@ -23,7 +23,6 @@ import 
org.apache.dubbo.rpc.cluster.router.script.ScriptStateRouterFactory;
 import org.apache.dubbo.rpc.cluster.router.state.StateRouter;
 import org.apache.dubbo.rpc.cluster.router.state.StateRouterFactory;
 
-import java.io.File;
 import java.io.FileReader;
 import java.io.IOException;
 
@@ -56,7 +55,7 @@ public class FileStateRouterFactory implements 
StateRouterFactory {
                     type = path.substring(i + 1);
                 }
             }
-            String rule = IOUtils.read(new FileReader(new 
File(url.getAbsolutePath())));
+            String rule = IOUtils.read(new FileReader(url.getAbsolutePath()));
 
             // FIXME: this code looks useless
             boolean runtime = url.getParameter(RUNTIME_KEY, false);
diff --git 
a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/tag/model/Tag.java
 
b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/tag/model/Tag.java
index d51482e..706384c 100644
--- 
a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/tag/model/Tag.java
+++ 
b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/tag/model/Tag.java
@@ -20,9 +20,6 @@ import java.util.List;
 import java.util.Map;
 import java.util.stream.Collectors;
 
-/**
- *
- */
 public class Tag {
     private String name;
     private List<String> addresses;
diff --git 
a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/AvailableClusterInvoker.java
 
b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/AvailableClusterInvoker.java
index 81208c5..cf71aa2 100644
--- 
a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/AvailableClusterInvoker.java
+++ 
b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/AvailableClusterInvoker.java
@@ -26,7 +26,7 @@ import org.apache.dubbo.rpc.cluster.LoadBalance;
 import java.util.List;
 
 /**
- * AvailableCluster
+ * AvailableClusterInvoker
  *
  */
 public class AvailableClusterInvoker<T> extends AbstractClusterInvoker<T> {
diff --git 
a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/BroadcastClusterInvoker.java
 
b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/BroadcastClusterInvoker.java
index 6b23b3a..93604aa 100644
--- 
a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/BroadcastClusterInvoker.java
+++ 
b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/BroadcastClusterInvoker.java
@@ -90,11 +90,16 @@ public class BroadcastClusterInvoker<T> extends 
AbstractClusterInvoker<T> {
 
         if (exception != null) {
             if (failIndex == failThresholdIndex) {
-                logger.debug(
+                if (logger.isDebugEnabled()) {
+                    logger.debug(
                         String.format("The number of BroadcastCluster call 
failures has reached the threshold %s", failThresholdIndex));
+
+                }
             } else {
-                logger.debug(String.format("The number of BroadcastCluster 
call failures has not reached the threshold %s, fail size is %s",
+                if (logger.isDebugEnabled()) {
+                    logger.debug(String.format("The number of BroadcastCluster 
call failures has not reached the threshold %s, fail size is %s",
                         failThresholdIndex, failIndex));
+                }
             }
             throw exception;
         }
@@ -103,7 +108,7 @@ public class BroadcastClusterInvoker<T> extends 
AbstractClusterInvoker<T> {
     }
 
     private RpcException getRpcException(Throwable throwable) {
-        RpcException rpcException = null;
+        RpcException rpcException;
         if (throwable instanceof RpcException) {
             rpcException = (RpcException) throwable;
         } else {
diff --git 
a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/registry/ZoneAwareClusterInvoker.java
 
b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/registry/ZoneAwareClusterInvoker.java
index f4b307b..b4bd540 100644
--- 
a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/registry/ZoneAwareClusterInvoker.java
+++ 
b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/registry/ZoneAwareClusterInvoker.java
@@ -40,7 +40,7 @@ import static 
org.apache.dubbo.common.constants.RegistryConstants.REGISTRY_ZONE_
 import static org.apache.dubbo.common.constants.RegistryConstants.ZONE_KEY;
 
 /**
- * When there're more than one registry for subscription.
+ * When there are more than one registry for subscription.
  * <p>
  * This extension provides a strategy to decide how to distribute traffics 
among them:
  * 1. registry marked as 'preferred=true' has the highest priority.
diff --git 
a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/wrapper/MockClusterInvoker.java
 
b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/wrapper/MockClusterInvoker.java
index 5ce1572..9ee1e39 100644
--- 
a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/wrapper/MockClusterInvoker.java
+++ 
b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/wrapper/MockClusterInvoker.java
@@ -107,11 +107,11 @@ public class MockClusterInvoker<T> implements 
ClusterInvoker<T> {
                 result = this.invoker.invoke(invocation);
 
                 //fix:#4585
-                if(result.getException() != null && result.getException() 
instanceof RpcException){
-                    RpcException rpcException= 
(RpcException)result.getException();
-                    if(rpcException.isBiz()){
-                        throw  rpcException;
-                    }else {
+                if (result.getException() != null && result.getException() 
instanceof RpcException) {
+                    RpcException rpcException = (RpcException) 
result.getException();
+                    if (rpcException.isBiz()) {
+                        throw rpcException;
+                    } else {
                         result = doMockInvoke(invocation, rpcException);
                     }
                 }
diff --git 
a/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/router/condition/ConditionRouterTest.java
 
b/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/router/condition/ConditionStateRouterTest.java
similarity index 99%
rename from 
dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/router/condition/ConditionRouterTest.java
rename to 
dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/router/condition/ConditionStateRouterTest.java
index e7fa859..5698dc6 100644
--- 
a/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/router/condition/ConditionRouterTest.java
+++ 
b/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/router/condition/ConditionStateRouterTest.java
@@ -37,7 +37,7 @@ import java.util.List;
 import static org.apache.dubbo.rpc.cluster.Constants.FORCE_KEY;
 import static org.apache.dubbo.rpc.cluster.Constants.RULE_KEY;
 
-public class ConditionRouterTest {
+public class ConditionStateRouterTest {
     private static final String LOCAL_HOST = "127.0.0.1";
     private URL SCRIPT_URL = 
URL.valueOf("condition://0.0.0.0/com.foo.BarService");
 
diff --git 
a/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/router/mesh/rule/virtualservice/match/DubboMethodMatchTest.java
 
b/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/router/mesh/rule/virtualservice/match/DubboMethodMatchTest.java
index c3498b6..a783f91 100644
--- 
a/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/router/mesh/rule/virtualservice/match/DubboMethodMatchTest.java
+++ 
b/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/router/mesh/rule/virtualservice/match/DubboMethodMatchTest.java
@@ -39,7 +39,6 @@ public class DubboMethodMatchTest {
 
         dubboMethodMatch.setName_match(nameStringMatch);
 
-        ;
         assertTrue(dubboMethodMatch.isMatch(new RpcInvocation(null, 
"sayHello", "",  "", new Class[]{}, new Object[]{})));
     }
 
@@ -50,8 +49,6 @@ public class DubboMethodMatchTest {
         dubboMethodMatch.setArgc(1);
 
         assertFalse(dubboMethodMatch.isMatch(new RpcInvocation(null, 
"sayHello", "",  "", new Class[]{}, new Object[]{})));
-        assertFalse(dubboMethodMatch.isMatch(new RpcInvocation(null, 
"sayHello", "",  "", new Class[]{}, new Object[]{})));
-
         assertTrue(dubboMethodMatch.isMatch(new RpcInvocation(null, 
"sayHello", "",  "", new Class[]{}, new Object[]{"1"})));
     }
 
diff --git 
a/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/router/tag/TagStateRouterTest.java
 
b/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/router/tag/TagStateRouterTest.java
index 60cbf44..18c1431 100644
--- 
a/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/router/tag/TagStateRouterTest.java
+++ 
b/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/router/tag/TagStateRouterTest.java
@@ -67,8 +67,6 @@ public class TagStateRouterTest {
         
when(moduleModel.getExtensionLoader(TracingContextProvider.class)).thenReturn(extensionLoader);
 
         url = 
URL.valueOf("test://localhost/DemoInterface").setScopeModel(moduleModel);
-
-        url = 
URL.valueOf("test://localhost/DemoInterface").setScopeModel(moduleModel);
     }
 
     @Test
diff --git 
a/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/support/wrapper/MockClusterInvokerTest.java
 
b/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/support/wrapper/MockClusterInvokerTest.java
index 9534fe4..aceec90 100644
--- 
a/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/support/wrapper/MockClusterInvokerTest.java
+++ 
b/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/support/wrapper/MockClusterInvokerTest.java
@@ -490,7 +490,7 @@ public class MockClusterInvokerTest {
         invocation.setMethodName("getSomething");
         Result ret = cluster.invoke(invocation);
         Assertions.assertTrue(ret.getValue() instanceof String, "result type 
must be String but was : " + ret.getValue().getClass());
-        Assertions.assertEquals("1688", (String) ret.getValue());
+        Assertions.assertEquals("1688", ret.getValue());
     }
 
     @Test
@@ -606,7 +606,7 @@ public class MockClusterInvokerTest {
         List<User> rl = (List<User>) ret.getValue();
         System.out.println(rl);
         Assertions.assertEquals(2, rl.size());
-        Assertions.assertEquals("hi1", ((User) rl.get(0)).getName());
+        Assertions.assertEquals("hi1", rl.get(0).getName());
     }
 
     @Test
@@ -641,7 +641,7 @@ public class MockClusterInvokerTest {
             cluster.invoke(invocation);
             Assertions.fail();
         } catch (RpcException e) {
-            Assertions.assertFalse(e.isBiz(), "not custem exception");
+            Assertions.assertFalse(e.isBiz(), "not custom exception");
         }
     }
 
diff --git 
a/dubbo-common/src/main/java/org/apache/dubbo/common/BaseServiceMetadata.java 
b/dubbo-common/src/main/java/org/apache/dubbo/common/BaseServiceMetadata.java
index d09b67e..58d0ac3 100644
--- 
a/dubbo-common/src/main/java/org/apache/dubbo/common/BaseServiceMetadata.java
+++ 
b/dubbo-common/src/main/java/org/apache/dubbo/common/BaseServiceMetadata.java
@@ -37,7 +37,7 @@ public class BaseServiceMetadata {
         int length = path == null ? 0 : path.length();
         length += group == null ? 0 : group.length();
         length += version == null ? 0 : version.length();
-        length += 3;
+        length += 2;
         StringBuilder buf = new StringBuilder(length);
         if (StringUtils.isNotEmpty(group)) {
             buf.append(group).append('/');
@@ -106,7 +106,7 @@ public class BaseServiceMetadata {
 
     public static String keyWithoutGroup(String interfaceName, String version) 
{
         if (StringUtils.isEmpty(version)) {
-            return interfaceName + ":0.0.0";
+            return interfaceName + ":" + DEFAULT_VERSION;
         }
         return interfaceName + ":" + version;
     }
diff --git 
a/dubbo-common/src/main/java/org/apache/dubbo/common/config/Environment.java 
b/dubbo-common/src/main/java/org/apache/dubbo/common/config/Environment.java
index b3bbbf1..e4aed19 100644
--- a/dubbo-common/src/main/java/org/apache/dubbo/common/config/Environment.java
+++ b/dubbo-common/src/main/java/org/apache/dubbo/common/config/Environment.java
@@ -162,7 +162,7 @@ public class Environment extends LifecycleAdapter 
implements ApplicationExt {
      * All configurations will be converged into a data bus - URL, and then 
drive the subsequent process.
      * <p>
      * At present, there are many configuration sources, including 
AbstractConfig (API, XML, annotation), - D, config center, etc.
-     * This method helps us to filter out the most priority values from 
various configuration sources.
+     * This methood helps us t filter out the most priority values from 
various configuration sources.
      *
      * @param config
      * @param prefix
diff --git 
a/dubbo-common/src/main/java/org/apache/dubbo/common/config/ModuleEnvironment.java
 
b/dubbo-common/src/main/java/org/apache/dubbo/common/config/ModuleEnvironment.java
index c177f51..cb6a820 100644
--- 
a/dubbo-common/src/main/java/org/apache/dubbo/common/config/ModuleEnvironment.java
+++ 
b/dubbo-common/src/main/java/org/apache/dubbo/common/config/ModuleEnvironment.java
@@ -27,6 +27,7 @@ import org.apache.dubbo.rpc.model.ModuleModel;
 import java.util.List;
 import java.util.Map;
 import java.util.Optional;
+import java.util.concurrent.atomic.AtomicBoolean;
 
 public class ModuleEnvironment extends Environment implements ModuleExt {
 
@@ -36,6 +37,8 @@ public class ModuleEnvironment extends Environment implements 
ModuleExt {
 
     public static final String NAME = "moduleEnvironment";
 
+    private AtomicBoolean initialized = new AtomicBoolean(false);
+
     private final ModuleModel moduleModel;
 
     private Environment applicationDelegate;
@@ -54,7 +57,9 @@ public class ModuleEnvironment extends Environment implements 
ModuleExt {
 
     @Override
     public void initialize() throws IllegalStateException {
-        this.orderedPropertiesConfiguration = new 
OrderedPropertiesConfiguration(moduleModel);
+        if (initialized.compareAndSet(false, true)) {
+            this.orderedPropertiesConfiguration = new 
OrderedPropertiesConfiguration(moduleModel);
+        }
     }
 
     @Override
diff --git 
a/dubbo-common/src/main/java/org/apache/dubbo/common/extension/ExtensionDirector.java
 
b/dubbo-common/src/main/java/org/apache/dubbo/common/extension/ExtensionDirector.java
index 1614748..ee03517 100644
--- 
a/dubbo-common/src/main/java/org/apache/dubbo/common/extension/ExtensionDirector.java
+++ 
b/dubbo-common/src/main/java/org/apache/dubbo/common/extension/ExtensionDirector.java
@@ -148,6 +148,8 @@ public class ExtensionDirector implements ExtensionAccessor 
{
                 extensionLoader.destroy();
             }
             extensionLoadersMap.clear();
+            extensionScopeMap.clear();
+            extensionPostProcessors.clear();
         }
     }
 
diff --git 
a/dubbo-common/src/main/java/org/apache/dubbo/rpc/model/ConsumerModel.java 
b/dubbo-common/src/main/java/org/apache/dubbo/rpc/model/ConsumerModel.java
index 129873c..72892d5 100644
--- a/dubbo-common/src/main/java/org/apache/dubbo/rpc/model/ConsumerModel.java
+++ b/dubbo-common/src/main/java/org/apache/dubbo/rpc/model/ConsumerModel.java
@@ -40,7 +40,7 @@ public class ConsumerModel extends ServiceModel {
     private Map<Method, ConsumerMethodModel> methodModels = new HashMap<>();
 
     /**
-     * This constructor create an instance of ConsumerModel and passed objects 
should not be null.
+     * This constructor creates an instance of ConsumerModel and passed 
objects should not be null.
      * If service name, service instance, proxy object,methods should not be 
null. If these are null
      * then this constructor will throw {@link IllegalArgumentException}
      *
diff --git 
a/dubbo-common/src/main/java/org/apache/dubbo/rpc/model/ModuleModel.java 
b/dubbo-common/src/main/java/org/apache/dubbo/rpc/model/ModuleModel.java
index 7958943..163273c 100644
--- a/dubbo-common/src/main/java/org/apache/dubbo/rpc/model/ModuleModel.java
+++ b/dubbo-common/src/main/java/org/apache/dubbo/rpc/model/ModuleModel.java
@@ -120,6 +120,11 @@ public class ModuleModel extends ScopeModel {
             moduleEnvironment = null;
         }
 
+        if (moduleConfigManager != null) {
+            moduleConfigManager.destroy();
+            moduleConfigManager = null;
+        }
+
         // destroy application if none pub module
         applicationModel.tryDestroy();
     }
diff --git 
a/dubbo-common/src/main/java/org/apache/dubbo/rpc/model/ProviderModel.java 
b/dubbo-common/src/main/java/org/apache/dubbo/rpc/model/ProviderModel.java
index f331952..a1d8772 100644
--- a/dubbo-common/src/main/java/org/apache/dubbo/rpc/model/ProviderModel.java
+++ b/dubbo-common/src/main/java/org/apache/dubbo/rpc/model/ProviderModel.java
@@ -153,8 +153,7 @@ public class ProviderModel extends ServiceModel {
     }
 
     private void initMethod(Class<?> serviceInterfaceClass) {
-        Method[] methodsToExport;
-        methodsToExport = serviceInterfaceClass.getMethods();
+        Method[] methodsToExport = serviceInterfaceClass.getMethods();
 
         for (Method method : methodsToExport) {
             method.setAccessible(true);
diff --git 
a/dubbo-common/src/main/java/org/apache/dubbo/rpc/model/ServiceMetadata.java 
b/dubbo-common/src/main/java/org/apache/dubbo/rpc/model/ServiceMetadata.java
index d838975..9111f80 100644
--- a/dubbo-common/src/main/java/org/apache/dubbo/rpc/model/ServiceMetadata.java
+++ b/dubbo-common/src/main/java/org/apache/dubbo/rpc/model/ServiceMetadata.java
@@ -17,7 +17,6 @@
 package org.apache.dubbo.rpc.model;
 
 import org.apache.dubbo.common.BaseServiceMetadata;
-import org.apache.dubbo.common.URL;
 
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
@@ -49,7 +48,7 @@ public class ServiceMetadata extends BaseServiceMetadata {
         this.defaultGroup = group;
         this.group = group;
         this.version = version;
-        this.serviceKey = URL.buildKey(serviceInterfaceName, group, version);
+        this.serviceKey = buildServiceKey(serviceInterfaceName, group, 
version);
         this.serviceType = serviceType;
     }
 
diff --git 
a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/ReferenceAnnotationBeanPostProcessor.java
 
b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/ReferenceAnnotationBeanPostProcessor.java
index 6a2d43c..b857202 100644
--- 
a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/ReferenceAnnotationBeanPostProcessor.java
+++ 
b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/ReferenceAnnotationBeanPostProcessor.java
@@ -177,7 +177,7 @@ public class ReferenceAnnotationBeanPostProcessor extends 
AbstractAnnotationBean
             // this is an early event, it will be notified at 
org.springframework.context.support.AbstractApplicationContext.registerListeners()
             applicationContext.publishEvent(new 
DubboConfigInitEvent(applicationContext));
         } catch (Exception e) {
-            // if spring version is less then 4.2, it does not support early 
application event
+            // if spring version is less than 4.2, it does not support early 
application event
             logger.warn("publish early application event failed, please 
upgrade spring version to 4.2.x or later: " + e);
         }
     }
@@ -358,7 +358,7 @@ public class ReferenceAnnotationBeanPostProcessor extends 
AbstractAnnotationBean
                 AnnotationAttributes attributes = methodElement.attributes;
                 String referenceBeanName = 
registerReferenceBean(methodElement.getPropertyName(), injectedType, 
attributes, methodElement.method);
 
-                //associate fieldElement and reference bean
+                //associate methodElement and reference bean
                 methodElement.injectedObject = referenceBeanName;
                 injectedMethodReferenceBeanCache.put(methodElement, 
referenceBeanName);
             }
@@ -495,7 +495,7 @@ public class ReferenceAnnotationBeanPostProcessor extends 
AbstractAnnotationBean
 
         beanDefinitionRegistry.registerBeanDefinition(referenceBeanName, 
beanDefinition);
         referenceBeanManager.registerReferenceKeyAndBeanName(referenceKey, 
referenceBeanName);
-        logger.info("Register dubbo reference bean: "+referenceBeanName+" = 
"+referenceKey+" at "+member);
+        logger.info("Register dubbo reference bean: " + referenceBeanName + " 
= " + referenceKey + " at " + member);
         return referenceBeanName;
     }
 
diff --git 
a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/ServiceAnnotationPostProcessor.java
 
b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/ServiceAnnotationPostProcessor.java
index 3351a41..5e91ecb 100644
--- 
a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/ServiceAnnotationPostProcessor.java
+++ 
b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/ServiceAnnotationPostProcessor.java
@@ -245,7 +245,7 @@ public class ServiceAnnotationPostProcessor implements 
BeanDefinitionRegistryPos
     }
 
     /**
-     * It'd better to use BeanNameGenerator instance that should reference
+     * It'd be better to use BeanNameGenerator instance that should reference
      * {@link ConfigurationClassPostProcessor#componentScanBeanNameGenerator},
      * thus it maybe a potential problem on bean name generation.
      *
diff --git 
a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/beans/factory/config/DubboConfigDefaultPropertyValueBeanPostProcessor.java
 
b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/beans/factory/config/DubboConfigDefaultPropertyValueBeanPostProcessor.java
index c29182c..dd07b91 100644
--- 
a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/beans/factory/config/DubboConfigDefaultPropertyValueBeanPostProcessor.java
+++ 
b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/beans/factory/config/DubboConfigDefaultPropertyValueBeanPostProcessor.java
@@ -91,7 +91,7 @@ public class DubboConfigDefaultPropertyValueBeanPostProcessor 
extends GenericBea
             Method setterMethod = propertyDescriptor.getWriteMethod();
             if (setterMethod != null) { // the getter and setter methods are 
present
                 if (Arrays.equals(of(String.class), 
setterMethod.getParameterTypes())) { // the param type is String
-                    // set bean name to the value of the the property
+                    // set bean name to the value of the property
                     invokeMethod(setterMethod, bean, beanName);
                 }
             }
diff --git 
a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/context/DubboConfigApplicationListener.java
 
b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/context/DubboConfigApplicationListener.java
index e1153e2..23c66f4 100644
--- 
a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/context/DubboConfigApplicationListener.java
+++ 
b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/context/DubboConfigApplicationListener.java
@@ -51,7 +51,7 @@ public class DubboConfigApplicationListener implements 
ApplicationListener<Dubbo
     @Override
     public void onApplicationEvent(DubboConfigInitEvent event) {
         if (nullSafeEquals(applicationContext, event.getSource())) {
-            // It's expected to be notify at 
org.springframework.context.support.AbstractApplicationContext.registerListeners(),
+            // It's expected to be notified at 
org.springframework.context.support.AbstractApplicationContext.registerListeners(),
             // before loading non-lazy singleton beans. At this moment, all 
BeanFactoryPostProcessor have been processed,
             if (initialized.compareAndSet(false, true)) {
                 initDubboConfigBeans();
diff --git 
a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/context/DubboSpringInitializer.java
 
b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/context/DubboSpringInitializer.java
index a8f7952..8e32bab 100644
--- 
a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/context/DubboSpringInitializer.java
+++ 
b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/context/DubboSpringInitializer.java
@@ -148,7 +148,7 @@ public class DubboSpringInitializer {
     }
 
     private static ConfigurableListableBeanFactory 
findBeanFactory(BeanDefinitionRegistry registry) {
-        ConfigurableListableBeanFactory beanFactory = null;
+        ConfigurableListableBeanFactory beanFactory;
         if (registry instanceof ConfigurableListableBeanFactory) {
             beanFactory = (ConfigurableListableBeanFactory) registry;
         } else if (registry instanceof GenericApplicationContext) {
diff --git 
a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/reference/ReferenceBeanSupport.java
 
b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/reference/ReferenceBeanSupport.java
index b22d032..52b0f67 100644
--- 
a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/reference/ReferenceBeanSupport.java
+++ 
b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/reference/ReferenceBeanSupport.java
@@ -90,7 +90,7 @@ public class ReferenceBeanSupport {
         // String[] registry => String registryIds
         String[] registryIds = (String[]) 
attributes.get(ReferenceAttributes.REGISTRY);
         if (registryIds != null) {
-            String value = join((String[]) registryIds, ",");
+            String value = join(registryIds, ",");
             attributes.remove(ReferenceAttributes.REGISTRY);
             attributes.put(ReferenceAttributes.REGISTRY_IDS, value);
         }
diff --git 
a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/util/DubboAnnotationUtils.java
 
b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/util/DubboAnnotationUtils.java
index 132990e..6656b75 100644
--- 
a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/util/DubboAnnotationUtils.java
+++ 
b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/util/DubboAnnotationUtils.java
@@ -77,7 +77,6 @@ public class DubboAnnotationUtils {
      * @throws IllegalStateException if interface name was not found
      */
     public static String resolveInterfaceName(Map<String, Object> attributes, 
Class<?> defaultInterfaceClass) {
-        Boolean generic = getAttribute(attributes, "generic");
         // 1. get from DubboService.interfaceName()
         String interfaceClassName = getAttribute(attributes, "interfaceName");
         if (StringUtils.hasText(interfaceClassName)) {
@@ -134,8 +133,8 @@ public class DubboAnnotationUtils {
     /**
      * Resolve the parameters of {@link 
org.apache.dubbo.config.annotation.DubboService}
      * and {@link org.apache.dubbo.config.annotation.DubboReference} from the 
specified.
-     * It iterate elements in order.The former element plays as key or 
key&value role, it would be
-     * spilt if it contain specific string, for instance, ":" and "=". As for 
later element can't
+     * It iterates elements in order.The former element plays as key or 
key&value role, it would be
+     * spilt if it contains specific string, for instance, ":" and "=". As for 
later element can't
      * be split in anytime.It will throw IllegalArgumentException If converted 
array length isn't
      * even number.
      * The convert cases below work in right way,which are best practice.
diff --git 
a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/util/DubboBeanUtils.java
 
b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/util/DubboBeanUtils.java
index c350348..420ae9e 100644
--- 
a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/util/DubboBeanUtils.java
+++ 
b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/util/DubboBeanUtils.java
@@ -53,7 +53,7 @@ import java.util.Map;
  */
 public interface DubboBeanUtils {
 
-    static final Log log = LogFactory.getLog(DubboBeanUtils.class);
+    Log log = LogFactory.getLog(DubboBeanUtils.class);
 
     /**
      * Register the common beans
diff --git 
a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/beans/factory/annotation/MethodConfigCallbackTest.java
 
b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/beans/factory/annotation/MethodConfigCallbackTest.java
index a0eac46..1ac71b4 100644
--- 
a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/beans/factory/annotation/MethodConfigCallbackTest.java
+++ 
b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/beans/factory/annotation/MethodConfigCallbackTest.java
@@ -68,7 +68,7 @@ public class MethodConfigCallbackTest {
     private ConfigurableApplicationContext context;
 
     @DubboReference(check = false, async = true,
-        injvm = false, // Currently local call is not supported method 
callback cause by Injvm protocol is not supported ClusterFilter
+        injvm = false, // Currently, local call is not supported method 
callback cause by Injvm protocol is not supported ClusterFilter
         methods = {@Method(name = "sayHello",
         oninvoke = "methodCallback.oninvoke1",
         onreturn = "methodCallback.onreturn1",
@@ -76,7 +76,7 @@ public class MethodConfigCallbackTest {
     private HelloService helloServiceMethodCallBack;
 
     @DubboReference(check = false, async = true,
-            injvm = false, // Currently local call is not supported method 
callback cause by Injvm protocol is not supported ClusterFilter
+            injvm = false, // Currently, local call is not supported method 
callback cause by Injvm protocol is not supported ClusterFilter
             methods = {@Method(name = "sayHello",
             oninvoke = "methodCallback.oninvoke2",
             onreturn = "methodCallback.onreturn2",
diff --git 
a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/beans/factory/annotation/ServiceBeanNameBuilderTest.java
 
b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/beans/factory/annotation/ServiceBeanNameBuilderTest.java
index a117ad5..07601a3 100644
--- 
a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/beans/factory/annotation/ServiceBeanNameBuilderTest.java
+++ 
b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/beans/factory/annotation/ServiceBeanNameBuilderTest.java
@@ -62,9 +62,6 @@ public class ServiceBeanNameBuilderTest {
         ServiceBeanNameBuilder builder = 
ServiceBeanNameBuilder.create(service, INTERFACE_CLASS, environment);
         
Assertions.assertEquals("ServiceBean:org.apache.dubbo.config.spring.api.DemoService:1.0.0:DUBBO",
                 builder.build());
-
-        
Assertions.assertEquals("ServiceBean:org.apache.dubbo.config.spring.api.DemoService:1.0.0:DUBBO",
-                builder.build());
     }
 
     @Test
diff --git 
a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/AbstractServiceNameMapping.java
 
b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/AbstractServiceNameMapping.java
index 9ef1fbb..66a77ca 100644
--- 
a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/AbstractServiceNameMapping.java
+++ 
b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/AbstractServiceNameMapping.java
@@ -155,6 +155,7 @@ public abstract class AbstractServiceNameMapping implements 
ServiceNameMapping,
                 removeListener(subscribeURL, listener);
             }
             if (CollectionUtils.isEmpty(listeners)) {
+                mappingListeners.remove(mappingKey);
                 removeCachedMapping(mappingKey);
                 removeMappingLock(mappingKey);
             }
diff --git 
a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/AbstractServiceDiscovery.java
 
b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/AbstractServiceDiscovery.java
index 6eabe18..7388a46 100644
--- 
a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/AbstractServiceDiscovery.java
+++ 
b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/AbstractServiceDiscovery.java
@@ -131,6 +131,9 @@ public abstract class AbstractServiceDiscovery implements 
ServiceDiscovery {
     public synchronized void unregister() throws RuntimeException {
         // fixme, this metadata info might still being shared by other 
instances
 //        unReportMetadata(this.metadataInfo);
+        if (!isValidInstance(this.serviceInstance)) {
+            return;
+        }
         doUnregister(this.serviceInstance);
     }
 
diff --git 
a/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/client/ServiceDiscoveryRegistryTest.java
 
b/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/client/ServiceDiscoveryRegistryTest.java
index a21e70b..6ce0410 100644
--- 
a/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/client/ServiceDiscoveryRegistryTest.java
+++ 
b/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/client/ServiceDiscoveryRegistryTest.java
@@ -251,7 +251,6 @@ public class ServiceDiscoveryRegistryTest {
         when(mapping.getCachedMapping(url2)).thenReturn(multiApps);
         serviceDiscoveryRegistry.doUnsubscribe(url2, testServiceListener2);
         assertEquals(1, serviceDiscoveryRegistry.getServiceListeners().size());
-        assertEquals(1, serviceDiscoveryRegistry.getServiceListeners().size());
         ServiceInstancesChangedListener instancesChangedListener = 
serviceDiscoveryRegistry.getServiceListeners().entrySet().iterator().next().getValue();
         assertTrue(instancesChangedListener.hasListeners());
         when(mapping.getCachedMapping(url)).thenReturn(multiApps);

Reply via email to