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

DiscoveryClient seems to fail with null pointer in some instances and not others #48

Closed
ljramones opened this issue Oct 30, 2014 · 2 comments

Comments

@ljramones
Copy link

I have used the DiscoveryClient in some instances and it seems to work fine, however in others it throws a NPE for no reason that I can determine. In all cases my spring boot app is annotated with @EnableEurekaClient

There are occasions when if I auto wire the DiscoveryClient such as

  @Autowired
    private DiscoveryClient discoveryClient;

and then later I call it via

 private InstanceInfo findLockManager() {
        InstanceInfo instance = null;
        try {
            instance = discoveryClient.getNextServerFromEureka(LOCK_MANAGER, false);
        } catch (RuntimeException e) {
            logger.error("Failed to find service " + LOCK_MANAGER, e);
            return null;
        }
        return instance;
    }

While running I see this

java.lang.NullPointerException: null
    at com.netflix.discovery.DiscoveryClient$$FastClassBySpringCGLIB$$a84c8cb4.invoke(<generated>)
    at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:708)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
    at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:133)
    at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:121)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:644)
    at com.netflix.discovery.DiscoveryClient$$EnhancerBySpringCGLIB$$4ff799f6.getNextServerFromEureka(<generated>)
    at com.cisco.services.rpil.management.NodeStatusManager.findLockManager(NodeStatusManager.java:153)
    at com.cisco.services.rpil.management.NodeStatusManager.setGlobalLock(NodeStatusManager.java:170)
    at com.cisco.services.rpil.management.NodeStatusManager.startup(NodeStatusManager.java:91)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleElement.invoke(InitDestroyAnnotationBeanPostProcessor.java:349)
    at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleMetadata.invokeInitMethods(InitDestroyAnnotationBeanPostProcessor.java:300)
    at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:133)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:407)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1545)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:703)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:109)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:691)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:320)
    at com.cisco.services.rpil.MicroServiceApplication.main(MicroServiceApplication.java:60)
@dsyer
Copy link
Contributor

dsyer commented Oct 31, 2014

It looks like NodeStatusManager.startup() is maybe @PostConstruct so you are trying to use the client before it is initialized. The EurekaClientConfiguration initializes the client but only as late as possible (to avoid other race conditions), which means in a Lifecycle.start() method. If you can move your initialization to happen later (lazily or in a SmartLifecycle.start() with order>0) it should have time to get ready before you need it.

@dsyer dsyer added the question label Oct 31, 2014
@ljramones
Copy link
Author

I changed the code to use a SmartLifecycle, put a high value in getPhase() override method and it seems fine now.
This is probably something to put in a FAQ.
Thanks.

@dsyer dsyer added this to the 1.0.0.M3 milestone Nov 5, 2014
@dsyer dsyer closed this as completed in bebcf66 Nov 5, 2014
dsyer added a commit that referenced this issue Dec 4, 2014
Blitz4j is definitely preventing the log levels from being changed at runtime
through the normal Spring boot channels.

Fixes gh-48
dsyer added a commit that referenced this issue Dec 4, 2014
Blitz4j is definitely preventing the log levels from being changed at runtime
through the normal Spring boot channels.

Fixes gh-48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants