dubbo icon indicating copy to clipboard operation
dubbo copied to clipboard

[Bug] moduleModel is null after native building

Open imgoby opened this issue 3 months ago • 6 comments

Pre-check

  • [x] I am sure that all the content I provide is in English.

Search before asking

  • [x] I had searched in the issues and found no similar issues.

Apache Dubbo Component

Java SDK (apache/dubbo)

Dubbo Version

    <dubbo.version>3.3.1</dubbo.version>

Steps to reproduce this issue

  1. build with native

2.run application:

2025-09-02 09:35:43,006 ERROR [main] o.s.boot.SpringApplication [SpringApplication.java : 822] Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dubboConfigBeanInitializer': Initialization dubbo config beans failed
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1770)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:598)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:520)
        at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:331)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:252)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:329)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:201)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:973)
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:950)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:614)
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:146)
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:732)
        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:434)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:310)
        at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:150)
        at com.hcll.sail.MessageProviderApplication.main(MessageProviderApplication.java:109)
Caused by: org.springframework.beans.FatalBeanException: Initialization dubbo config beans failed
        at org.apache.dubbo.config.spring.context.DubboConfigBeanInitializer.init(DubboConfigBeanInitializer.java:89)
        at org.apache.dubbo.config.spring.context.DubboConfigBeanInitializer.afterPropertiesSet(DubboConfigBeanInitializer.java:77)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1817)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1766)
        ... 15 common frames omitted
Caused by: java.lang.NullPointerException: null
        at org.apache.dubbo.config.spring.reference.ReferenceBeanManager.initReferenceBean(ReferenceBeanManager.java:208)
        at org.apache.dubbo.config.spring.reference.ReferenceBeanManager.prepareReferenceBeans(ReferenceBeanManager.java:165)
        at org.apache.dubbo.config.spring.context.DubboConfigBeanInitializer.init(DubboConfigBeanInitializer.java:87)
        ... 18 common frames omitted
2025-09-02 09:36:51,105 INFO [background-preinit] o.h.validator.internal.util.Version [Version.java : 21] HV000001: Hibernate Validator 8.0.1.Final
2025-09-02 09:36:51,281 INFO [main] o.a.d.s.b.c.e.WelcomeLogoApplicationListener [Log4j2Logger.java : 71]  [DUBBO]

What you expected to happen

NullPointerException was found.I expect it normally

Anything else

I should add this code to fix it:

Image
        //fix bug,在native下moduleModel为null
        if (moduleModel == null) {
            moduleModel = DubboBeanUtils.getModuleModel(applicationContext);
        }

Are you willing to submit a pull request to fix on your own?

  • [ ] Yes I am willing to submit a pull request on my own!

Code of Conduct

imgoby avatar Sep 02 '25 02:09 imgoby

@zrlw @imgoby I’d like to work on this. Could you please assign it to me?

kyounghunJang avatar Oct 05 '25 08:10 kyounghunJang

could you debug or add log info at ReferenceBeanManager#setApplicationContext to check the moduleModel value?

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
        moduleModel = DubboBeanUtils.getModuleModel(applicationContext); 
        <=== debug or log info of moduleModel's value at here.
    }

moduleModel = DubboBeanUtils.getModuleModel(applicationContext); might be moved to prepareReferenceBeans

    public void prepareReferenceBeans() throws Exception {
        initialized = true;
        moduleModel = DubboBeanUtils.getModuleModel(applicationContext);  <<== moved to here
        for (ReferenceBean referenceBean : getReferences()) {
            initReferenceBean(referenceBean);
        }
    }

zrlw avatar Oct 18 '25 06:10 zrlw

could you debug or add log info at ReferenceBeanManager#setApplicationContext to check the moduleModel value?

Yes, I have added logs at this point, and that value is null. I spent a long time investigating this null value, and eventually had no choice but to add a fix at the end. Although this fix may not be the best solution, it has resolved the issue for now. I hope you can find the root cause and best way.

imgoby avatar Oct 18 '25 11:10 imgoby

prepareReferenceBeans

OK,this solution by moving to prepareReferenceBeans will be tried later.

imgoby avatar Oct 18 '25 11:10 imgoby

I hope you can find the root cause and best way.

it might be too early to get moduleModel at ReferenceBeanManager#setApplicationContext because it might not be created yet.

zrlw avatar Oct 19 '25 13:10 zrlw

prepareReferenceBeans

OK,this solution by moving to prepareReferenceBeans will be tried later.

any progress? @imgoby

zrlw avatar Nov 13 '25 06:11 zrlw