yhs0092 commented on issue #3977:
URL: 
https://github.com/apache/servicecomb-java-chassis/issues/3977#issuecomment-1769752560

   这里还有一个日志打印的优化项, 
   
https://github.com/apache/servicecomb-java-chassis/blob/4f59e71f5607b642f38fe07172d2c8a3acffe218/core/src/main/java/org/apache/servicecomb/core/SCBEngine.java#L319-L338
   
   在`SCBEngine#run`方法中, `printServiceInfo()`方法是在`finally`语句块中调用的, 
这个方法需要从`RegistryUtils`获取一些微服务信息, 依赖于注册发现模块初始化成功. 因此, 
可能SCBEngine的初始化流程在注册发现模块初始化完成之前就抛出异常, 在finally中调用`printServiceInfo()`, 
由于`RegistryUtils`还没有初始化`serviceRegistry`属性, 会再触发一个空指针异常, 
实际上打印在标准输出里的错误信息是第二个空指针异常, 掩盖了问题根因, 标准输出打印的错误信息如下:
   ```
   java.lang.NullPointerException
        at 
org.apache.servicecomb.serviceregistry.RegistryUtils.getAppId(RegistryUtils.java:162)
        at 
org.apache.servicecomb.serviceregistry.ServiceCenterRegistration.getAppId(ServiceCenterRegistration.java:72)
        at 
org.apache.servicecomb.registry.RegistrationManager.lambda$info$5(RegistrationManager.java:320)
        at java.util.ArrayList.forEach(ArrayList.java:1259)
        at 
org.apache.servicecomb.registry.RegistrationManager.info(RegistrationManager.java:318)
        at 
org.apache.servicecomb.core.bootup.ServiceInformationCollector.collect(ServiceInformationCollector.java:26)
        at 
org.apache.servicecomb.core.bootup.BootUpInformationCollector.collect(BootUpInformationCollector.java:24)
        at 
org.apache.servicecomb.core.SCBEngine.printServiceInfo(SCBEngine.java:349)
        at org.apache.servicecomb.core.SCBEngine.run(SCBEngine.java:338)
        at 
org.apache.servicecomb.core.SCBApplicationListener.onApplicationEvent(SCBApplicationListener.java:89)
        at 
org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:176)
        at 
org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:169)
        at 
org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:143)
        at 
org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:421)
        at 
org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:378)
        at 
org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:940)
        at 
org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:586)
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to