Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2.6.5问题,ReferenceAnnotationBeanPostProcessor$ReferenceBeanInvocationHandler#bean #2855

Closed
gMan1990 opened this issue Nov 30, 2018 · 8 comments
Assignees
Labels
type/bug Bugs to being fixed
Milestone

Comments

@gMan1990
Copy link

  • dubbo: 2.6.5
  • 测试,所以提供者和消费者在同一个jvm里

ReferenceBeanInvocationHandler的invoke就是消费者方法执行后会调用到的方法,它有个init方法用来初始化bean字段,这个方法有两处调用:

  1. https://github.com/apache/incubator-dubbo/blob/38e0f15be33a5edb35b45d2c5d7c6be753bdd888/dubbo-config/dubbo-config-spring/src/main/java/com/alibaba/dubbo/config/spring/beans/factory/annotation/ReferenceAnnotationBeanPostProcessor.java#L128
private InvocationHandler buildInvocationHandler(String referencedBeanName, ReferenceBean referenceBean) {
    ReferenceBeanInvocationHandler handler = localReferenceBeanInvocationHandlerCache.get(referencedBeanName);
    if (handler == null) {
        handler = new ReferenceBeanInvocationHandler(referenceBean);
    }
    if (applicationContext.containsBean(referencedBeanName)) { // Is local @Service Bean or not ?
        // ReferenceBeanInvocationHandler's initialization has to wait for current local @Service Bean has been exported.
        localReferenceBeanInvocationHandlerCache.put(referencedBeanName, handler);
    } else {
        // Remote Reference Bean should initialize immediately
        handler.init();
    }
    return handler;
}
  1. https://github.com/apache/incubator-dubbo/blob/38e0f15be33a5edb35b45d2c5d7c6be753bdd888/dubbo-config/dubbo-config-spring/src/main/java/com/alibaba/dubbo/config/spring/beans/factory/annotation/ReferenceAnnotationBeanPostProcessor.java#L230
private void initReferenceBeanInvocationHandler(ServiceBean serviceBean) {
    String serviceBeanName = serviceBean.getBeanName();
    // Remove ServiceBean when it's exported
    ReferenceBeanInvocationHandler handler = localReferenceBeanInvocationHandlerCache.remove(serviceBeanName);
    // Initialize
    if (handler != null) {
        handler.init();
    }
}

因为是测试所以:1处走的是if (applicationContext.containsBean(referencedBeanName))里面,不会调用handler.init();,2处我断点到handler都是null所以也不会调用handler.init();
所以那个bean字段都是null。然后执行invoke方法就是:

java.lang.NullPointerException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.alibaba.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor$ReferenceBeanInvocationHandler.invoke(ReferenceAnnotationBeanPostProcessor.java:159)
@mercyblitz mercyblitz self-assigned this Dec 3, 2018
@mercyblitz mercyblitz added the type/bug Bugs to being fixed label Dec 3, 2018
@mercyblitz
Copy link
Contributor

Thanks for your report, We also found this issue, will be fixed on 2.6.6

@mercyblitz mercyblitz added this to the 2.6.6 milestone Dec 3, 2018
@tswstarplanet
Copy link
Contributor

请问是protocol配置成injvm吗?

@gMan1990
Copy link
Author

gMan1990 commented Dec 8, 2018

@tswstarplanet 没有,是com.alibaba.dubbo.config.ReferenceConfig#createProxy方法自己查找提供者的

@mercyblitz
Copy link
Contributor

@gMan1990
Actually, all services annotated @Service should be exported before ReferenceBean#afterPropertiesSet() method executation.

@tswstarplanet
Copy link
Contributor

能提供demo吗?我自己复现没出现这个问题

@gMan1990
Copy link
Author

@tswstarplanet

ReferenceBeanInvocationHandler的invoke就是消费者方法执行后会调用到的方法,它有个init方法用来初始化bean字段,这个方法有两处调用

你先看下这个是不是两处调用,每处调用debug下,看是否和我说的一样:

因为是测试所以:1处走的是if (applicationContext.containsBean(referencedBeanName))里面,不会调用handler.init();,2处我断点到handler都是null所以也不会调用handler.init();
所以那个bean字段都是null

然后执行invoke方法,看那个bean字段是否为null

@mercyblitz
Copy link
Contributor

The duplicated issue : #3429

@flyer5200
Copy link

Thanks for your report, We also found this issue, will be fixed on 2.6.6

This problem still exists in 2.6.6 or 2.7.0, please confirm!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/bug Bugs to being fixed
Projects
None yet
Development

No branches or pull requests

4 participants