[ 
https://issues.apache.org/jira/browse/SCB-753?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16547553#comment-16547553
 ] 

ASF GitHub Bot commented on SCB-753:
------------------------------------

liubao68 closed pull request #814: [SCB-753]NPE when query not exists service
URL: https://github.com/apache/incubator-servicecomb-java-chassis/pull/814
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git 
a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/client/LocalServiceRegistryClientImpl.java
 
b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/client/LocalServiceRegistryClientImpl.java
index c753feab5..877b886f8 100644
--- 
a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/client/LocalServiceRegistryClientImpl.java
+++ 
b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/client/LocalServiceRegistryClientImpl.java
@@ -272,6 +272,9 @@ protected Microservice findLatest(String appId, String 
serviceName, VersionRule
       String strVersionRule) {
     MicroserviceInstances instances =
         findServiceInstances(selfMicroserviceId, appId, serviceName, 
strVersionRule, null);
+    if(instances.isMicroserviceNotExist()) {
+      return null;
+    }
     return instances.getInstancesResponse().getInstances();
   }
 
@@ -291,8 +294,7 @@ public MicroserviceInstances findServiceInstances(String 
selfMicroserviceId, Str
     VersionRule versionRule = VersionRuleUtils.getOrCreate(strVersionRule);
     Microservice latestMicroservice = findLatest(appId, serviceName, 
versionRule);
     if (latestMicroservice == null) {
-      response.setInstances(allInstances);
-      microserviceInstances.setInstancesResponse(response);
+      microserviceInstances.setMicroserviceNotExist(true);
       return microserviceInstances;
     }
 
diff --git 
a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/registry/AbstractServiceRegistry.java
 
b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/registry/AbstractServiceRegistry.java
index 7257e95bd..e6aba3b52 100644
--- 
a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/registry/AbstractServiceRegistry.java
+++ 
b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/registry/AbstractServiceRegistry.java
@@ -223,7 +223,7 @@ public boolean unregisterInstance() {
   public List<MicroserviceInstance> findServiceInstance(String appId, String 
serviceName,
       String versionRule) {
     MicroserviceInstances instances = findServiceInstances(appId, serviceName, 
versionRule, null);
-    if (instances == null) {
+    if (instances == null || instances.isMicroserviceNotExist()) {
       return null;
     }
     return instances.getInstancesResponse().getInstances();
diff --git 
a/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/TestRegistry.java
 
b/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/TestRegistry.java
index 8237ef44c..548f21e23 100644
--- 
a/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/TestRegistry.java
+++ 
b/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/TestRegistry.java
@@ -99,6 +99,9 @@ public void testDelegate() {
     Assert.assertEquals(1, instanceList.size());
     Assert.assertEquals(RegistryUtils.getMicroservice().getServiceId(), 
instanceList.get(0).getServiceId());
 
+    instanceList = RegistryUtils.findServiceInstance("default", "notExists", 
"0.0.1");
+    Assert.assertEquals(null, instanceList);
+
     MicroserviceInstances microserviceInstances =
         RegistryUtils.findServiceInstances("default", "default", "0.0.1", "0");
     List<MicroserviceInstance> instanceLists = 
microserviceInstances.getInstancesResponse().getInstances();
diff --git 
a/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/client/LocalServiceRegistryClientImplTest.java
 
b/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/client/LocalServiceRegistryClientImplTest.java
index 7e95be93e..e4fdc7dcf 100644
--- 
a/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/client/LocalServiceRegistryClientImplTest.java
+++ 
b/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/client/LocalServiceRegistryClientImplTest.java
@@ -121,13 +121,12 @@ public void findServiceInstance_noInstances() {
     List<MicroserviceInstance> result =
         registryClient.findServiceInstance("self", appId, microserviceName, 
DefinitionConst.VERSION_RULE_ALL);
 
-    Assert.assertThat(result, Matchers.empty());
+    Assert.assertThat(result, Matchers.nullValue());
 
     MicroserviceInstances microserviceInstances =
         registryClient.findServiceInstances("self", appId, microserviceName, 
DefinitionConst.VERSION_RULE_ALL, null);
-    List<MicroserviceInstance> results = 
microserviceInstances.getInstancesResponse().getInstances();
-
-    Assert.assertThat(results, Matchers.empty());
+    Assert.assertThat(microserviceInstances.isMicroserviceNotExist(), 
Matchers.is(true));
+    Assert.assertThat(microserviceInstances.getInstancesResponse(), 
Matchers.nullValue());
   }
 
   @Test


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


> NPE when query not exists service
> ---------------------------------
>
>                 Key: SCB-753
>                 URL: https://issues.apache.org/jira/browse/SCB-753
>             Project: Apache ServiceComb
>          Issue Type: Bug
>            Reporter: liubao
>            Assignee: liubao
>            Priority: Major
>             Fix For: java-chassis-1.0.0
>
>
> 2018-07-17 21:09:18,350 [datafactory-2-1] ERROR send monitor data error. 
> [com.huawei.paas.monitor.DataFactory.lambda$start$0(DataFactory.java:68)]
> java.lang.NullPointerException
> at 
> org.apache.servicecomb.serviceregistry.registry.AbstractServiceRegistry.findServiceInstance(AbstractServiceRegistry.java:229)
> at 
> org.apache.servicecomb.serviceregistry.RegistryUtils.findServiceInstance(RegistryUtils.java:210)
> at 
> com.huawei.paas.monitor.DefaultMonitorDataPublisher$AddressManager.nextServer(DefaultMonitorDataPublisher.java:101)
> at 
> com.huawei.paas.monitor.DefaultMonitorDataPublisher.publish(DefaultMonitorDataPublisher.java:155)
> at com.huawei.paas.monitor.DataFactory.sendData(DataFactory.java:81)
> at com.huawei.paas.monitor.DataFactory.lambda$start$0(DataFactory.java:66)
> at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
> at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)
> at 
> java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180)
> at 
> java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294)
> at 
> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
> at 
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
> at 
> io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
> at java.lang.Thread.run(Thread.java:745)



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to