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

huxing pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-dubbo.git


The following commit(s) were added to refs/heads/master by this push:
     new b8a7a39  Remove unnecessary null check. (#1764)
b8a7a39 is described below

commit b8a7a399507cac33ccc410528fab4d89fe393204
Author: liaozan <[email protected]>
AuthorDate: Sat May 12 20:44:10 2018 +0800

    Remove unnecessary null check. (#1764)
---
 .../dubbo/config/spring/AnnotationBean.java        | 83 +++++++++++-----------
 1 file changed, 41 insertions(+), 42 deletions(-)

diff --git 
a/dubbo-config/dubbo-config-spring/src/main/java/com/alibaba/dubbo/config/spring/AnnotationBean.java
 
b/dubbo-config/dubbo-config-spring/src/main/java/com/alibaba/dubbo/config/spring/AnnotationBean.java
index bbb75d9..6da7ba8 100644
--- 
a/dubbo-config/dubbo-config-spring/src/main/java/com/alibaba/dubbo/config/spring/AnnotationBean.java
+++ 
b/dubbo-config/dubbo-config-spring/src/main/java/com/alibaba/dubbo/config/spring/AnnotationBean.java
@@ -33,6 +33,7 @@ import com.alibaba.dubbo.config.RegistryConfig;
 import com.alibaba.dubbo.config.ServiceConfig;
 import com.alibaba.dubbo.config.annotation.Reference;
 import com.alibaba.dubbo.config.annotation.Service;
+
 import org.springframework.beans.BeansException;
 import org.springframework.beans.factory.DisposableBean;
 import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
@@ -75,7 +76,7 @@ public class AnnotationBean extends AbstractConfig implements 
DisposableBean, Be
     public void setPackage(String annotationPackage) {
         this.annotationPackage = annotationPackage;
         this.annotationPackages = (annotationPackage == null || 
annotationPackage.length() == 0) ? null
-                : Constants.COMMA_SPLIT_PATTERN.split(annotationPackage);
+            : Constants.COMMA_SPLIT_PATTERN.split(annotationPackage);
     }
 
     @Override
@@ -85,7 +86,7 @@ public class AnnotationBean extends AbstractConfig implements 
DisposableBean, Be
 
     @Override
     public void postProcessBeanFactory(ConfigurableListableBeanFactory 
beanFactory)
-            throws BeansException {
+        throws BeansException {
         if (annotationPackage == null || annotationPackage.length() == 0) {
             return;
         }
@@ -110,7 +111,7 @@ public class AnnotationBean extends AbstractConfig 
implements DisposableBean, Be
     }
 
     @Override
-    public void destroy() throws Exception {
+    public void destroy() {
 
         //  This will only be called for singleton scope bean, and expected to 
be called by spring shutdown hook when BeanFactory/ApplicationContext destroys.
         //  We will guarantee dubbo related resources being released with 
dubbo shutdown hook.
@@ -134,7 +135,7 @@ public class AnnotationBean extends AbstractConfig 
implements DisposableBean, Be
 
     @Override
     public Object postProcessAfterInitialization(Object bean, String beanName)
-            throws BeansException {
+        throws BeansException {
         if (!isMatchPackage(bean)) {
             return bean;
         }
@@ -143,7 +144,7 @@ public class AnnotationBean extends AbstractConfig 
implements DisposableBean, Be
             ServiceBean<Object> serviceConfig = new 
ServiceBean<Object>(service);
             serviceConfig.setRef(bean);
             if (void.class.equals(service.interfaceClass())
-                    && "".equals(service.interfaceName())) {
+                && "".equals(service.interfaceName())) {
                 if (bean.getClass().getInterfaces().length > 0) {
                     
serviceConfig.setInterface(bean.getClass().getInterfaces()[0]);
                 } else {
@@ -152,37 +153,35 @@ public class AnnotationBean extends AbstractConfig 
implements DisposableBean, Be
             }
             if (applicationContext != null) {
                 serviceConfig.setApplicationContext(applicationContext);
-                if (service.registry() != null && service.registry().length > 
0) {
+                if (service.registry().length > 0) {
                     List<RegistryConfig> registryConfigs = new 
ArrayList<RegistryConfig>();
                     for (String registryId : service.registry()) {
                         if (registryId != null && registryId.length() > 0) {
-                            registryConfigs.add((RegistryConfig) 
applicationContext.getBean(registryId, RegistryConfig.class));
+                            
registryConfigs.add(applicationContext.getBean(registryId, 
RegistryConfig.class));
                         }
                     }
                     serviceConfig.setRegistries(registryConfigs);
                 }
-                if (service.provider() != null && service.provider().length() 
> 0) {
-                    serviceConfig.setProvider((ProviderConfig) 
applicationContext.getBean(service.provider(), ProviderConfig.class));
+                if (service.provider().length() > 0) {
+                    
serviceConfig.setProvider(applicationContext.getBean(service.provider(), 
ProviderConfig.class));
                 }
-                if (service.monitor() != null && service.monitor().length() > 
0) {
-                    serviceConfig.setMonitor((MonitorConfig) 
applicationContext.getBean(service.monitor(), MonitorConfig.class));
+                if (service.monitor().length() > 0) {
+                    
serviceConfig.setMonitor(applicationContext.getBean(service.monitor(), 
MonitorConfig.class));
                 }
-                if (service.application() != null && 
service.application().length() > 0) {
-                    serviceConfig.setApplication((ApplicationConfig) 
applicationContext.getBean(service.application(), ApplicationConfig.class));
+                if (service.application().length() > 0) {
+                    
serviceConfig.setApplication(applicationContext.getBean(service.application(), 
ApplicationConfig.class));
                 }
-                if (service.module() != null && service.module().length() > 0) 
{
-                    serviceConfig.setModule((ModuleConfig) 
applicationContext.getBean(service.module(), ModuleConfig.class));
+                if (service.module().length() > 0) {
+                    
serviceConfig.setModule(applicationContext.getBean(service.module(), 
ModuleConfig.class));
                 }
-                if (service.provider() != null && service.provider().length() 
> 0) {
-                    serviceConfig.setProvider((ProviderConfig) 
applicationContext.getBean(service.provider(), ProviderConfig.class));
-                } else {
-
+                if (service.provider().length() > 0) {
+                    
serviceConfig.setProvider(applicationContext.getBean(service.provider(), 
ProviderConfig.class));
                 }
-                if (service.protocol() != null && service.protocol().length > 
0) {
+                if (service.protocol().length > 0) {
                     List<ProtocolConfig> protocolConfigs = new 
ArrayList<ProtocolConfig>();
                     for (String protocolId : service.protocol()) {
                         if (protocolId != null && protocolId.length() > 0) {
-                            protocolConfigs.add((ProtocolConfig) 
applicationContext.getBean(protocolId, ProtocolConfig.class));
+                            
protocolConfigs.add(applicationContext.getBean(protocolId, 
ProtocolConfig.class));
                         }
                     }
                     serviceConfig.setProtocols(protocolConfigs);
@@ -190,7 +189,7 @@ public class AnnotationBean extends AbstractConfig 
implements DisposableBean, Be
                 try {
                     serviceConfig.afterPropertiesSet();
                 } catch (RuntimeException e) {
-                    throw (RuntimeException) e;
+                    throw e;
                 } catch (Exception e) {
                     throw new IllegalStateException(e.getMessage(), e);
                 }
@@ -203,7 +202,7 @@ public class AnnotationBean extends AbstractConfig 
implements DisposableBean, Be
 
     @Override
     public Object postProcessBeforeInitialization(Object bean, String beanName)
-            throws BeansException {
+        throws BeansException {
         if (!isMatchPackage(bean)) {
             return bean;
         }
@@ -211,15 +210,15 @@ public class AnnotationBean extends AbstractConfig 
implements DisposableBean, Be
         for (Method method : methods) {
             String name = method.getName();
             if (name.length() > 3 && name.startsWith("set")
-                    && method.getParameterTypes().length == 1
-                    && Modifier.isPublic(method.getModifiers())
-                    && !Modifier.isStatic(method.getModifiers())) {
+                && method.getParameterTypes().length == 1
+                && Modifier.isPublic(method.getModifiers())
+                && !Modifier.isStatic(method.getModifiers())) {
                 try {
                     Reference reference = 
method.getAnnotation(Reference.class);
                     if (reference != null) {
                         Object value = refer(reference, 
method.getParameterTypes()[0]);
                         if (value != null) {
-                            method.invoke(bean, new Object[]{value});
+                            method.invoke(bean, value);
                         }
                     }
                 } catch (Throwable e) {
@@ -263,40 +262,40 @@ public class AnnotationBean extends AbstractConfig 
implements DisposableBean, Be
         if (referenceConfig == null) {
             referenceConfig = new ReferenceBean<Object>(reference);
             if (void.class.equals(reference.interfaceClass())
-                    && "".equals(reference.interfaceName())
-                    && referenceClass.isInterface()) {
+                && "".equals(reference.interfaceName())
+                && referenceClass.isInterface()) {
                 referenceConfig.setInterface(referenceClass);
             }
             if (applicationContext != null) {
                 referenceConfig.setApplicationContext(applicationContext);
-                if (reference.registry() != null && 
reference.registry().length > 0) {
+                if (reference.registry().length > 0) {
                     List<RegistryConfig> registryConfigs = new 
ArrayList<RegistryConfig>();
                     for (String registryId : reference.registry()) {
                         if (registryId != null && registryId.length() > 0) {
-                            registryConfigs.add((RegistryConfig) 
applicationContext.getBean(registryId, RegistryConfig.class));
+                            
registryConfigs.add(applicationContext.getBean(registryId, 
RegistryConfig.class));
                         }
                     }
                     referenceConfig.setRegistries(registryConfigs);
                 }
-                if (reference.consumer() != null && 
reference.consumer().length() > 0) {
-                    referenceConfig.setConsumer((ConsumerConfig) 
applicationContext.getBean(reference.consumer(), ConsumerConfig.class));
+                if (reference.consumer().length() > 0) {
+                    
referenceConfig.setConsumer(applicationContext.getBean(reference.consumer(), 
ConsumerConfig.class));
                 }
-                if (reference.monitor() != null && 
reference.monitor().length() > 0) {
-                    referenceConfig.setMonitor((MonitorConfig) 
applicationContext.getBean(reference.monitor(), MonitorConfig.class));
+                if (reference.monitor().length() > 0) {
+                    
referenceConfig.setMonitor(applicationContext.getBean(reference.monitor(), 
MonitorConfig.class));
                 }
-                if (reference.application() != null && 
reference.application().length() > 0) {
-                    referenceConfig.setApplication((ApplicationConfig) 
applicationContext.getBean(reference.application(), ApplicationConfig.class));
+                if (reference.application().length() > 0) {
+                    
referenceConfig.setApplication(applicationContext.getBean(reference.application(),
 ApplicationConfig.class));
                 }
-                if (reference.module() != null && reference.module().length() 
> 0) {
-                    referenceConfig.setModule((ModuleConfig) 
applicationContext.getBean(reference.module(), ModuleConfig.class));
+                if (reference.module().length() > 0) {
+                    
referenceConfig.setModule(applicationContext.getBean(reference.module(), 
ModuleConfig.class));
                 }
-                if (reference.consumer() != null && 
reference.consumer().length() > 0) {
-                    referenceConfig.setConsumer((ConsumerConfig) 
applicationContext.getBean(reference.consumer(), ConsumerConfig.class));
+                if (reference.consumer().length() > 0) {
+                    
referenceConfig.setConsumer(applicationContext.getBean(reference.consumer(), 
ConsumerConfig.class));
                 }
                 try {
                     referenceConfig.afterPropertiesSet();
                 } catch (RuntimeException e) {
-                    throw (RuntimeException) e;
+                    throw e;
                 } catch (Exception e) {
                     throw new IllegalStateException(e.getMessage(), e);
                 }

-- 
To stop receiving notification emails like this one, please contact
[email protected].

Reply via email to