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

Fix occure the NPE when SpringMVC and hystrix work together #1256

Merged
merged 2 commits into from May 24, 2018

Conversation

ascrutae
Copy link
Member

Please answer these questions before submitting pull request

@ascrutae ascrutae added the bug Something isn't working and you are sure it's a bug! label May 22, 2018
@ascrutae ascrutae added this to the 5.0.0-beta2 milestone May 22, 2018
@ascrutae ascrutae requested a review from wu-sheng May 22, 2018 23:57
@ascrutae ascrutae force-pushed the fix/hystrix-springmvc branch 2 times, most recently from 8f5e2f1 to 4a1846d Compare May 23, 2018 02:53
@coveralls
Copy link

coveralls commented May 23, 2018

Coverage Status

Coverage decreased (-0.004%) to 23.87% when pulling 3d967bd on ascrutae:fix/hystrix-springmvc into 29f6f6e on apache:master.

Copy link
Member

@wu-sheng wu-sheng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@candyleer could you verify this pr? I think you have some cases.

@candyleer
Copy link
Member

ok,I will test in last case

@candyleer
Copy link
Member

@ascrutae I have tested in my case,but it also has NPE

this method will be invoked twice ,and sencond one will throw NPE,
1.works good
image
2.NPE
image
(NativeWebRequest)objInst.getSkyWalkingDynamicField() is null

and they are in the same thread

NPE

ERROR 2018-05-23 23:40:18 InstMethodsInter :  class[class org.springframework.web.method.HandlerMethod] after method[getBean] intercept failure
java.lang.NullPointerException
	at org.apache.skywalking.apm.plugin.spring.mvc.commons.interceptor.GetBeanInterceptor.afterMethod(GetBeanInterceptor.java:51)
	at org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstMethodsInter.intercept(InstMethodsInter.java:105)
	at org.springframework.web.method.HandlerMethod.getBean(HandlerMethod.java)
	at org.springframework.web.servlet.handler.AbstractHandlerMethodExceptionResolver.shouldApplyTo(AbstractHandlerMethodExceptionResolver.java:47)
	at org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver.resolveException(AbstractHandlerExceptionResolver.java:131)
	at org.springframework.web.servlet.handler.HandlerExceptionResolverComposite.resolveException(HandlerExceptionResolverComposite.java:76)
	at org.springframework.web.servlet.DispatcherServlet.processHandlerException(DispatcherServlet.java:1222)
	at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1034)
	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:984)
	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:901)
	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
	at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:635)
	at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at com.example.test.CustomFilter.doFilter(CustomFilter.java:37)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)

@candyleer
Copy link
Member

candyleer commented May 23, 2018

maybe you can modify like this?

 @Override
    public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
        Object ret) throws Throwable {
        if (ret instanceof EnhancedInstance && objInst instanceof InvocableHandlerMethod) {
            ContextManager.getRuntimeContext().put(REQUEST_KEY_IN_RUNTIME_CONTEXT, ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest());
            ContextManager.getRuntimeContext().put(RESPONSE_KEY_IN_RUNTIME_CONTEXT, ((NativeWebRequest)objInst.getSkyWalkingDynamicField()).getNativeResponse());
        }
        return ret;
    }

@ascrutae
Copy link
Member Author

I had fix this. maybe you can try

@ascrutae
Copy link
Member Author

Here is the test report

@wu-sheng
Copy link
Member

Here is the test report

Thanks. Continue to wait for @candyleer feedback. :)

@candyleer
Copy link
Member

test passed.
image

image

Thanks.

@wu-sheng wu-sheng merged commit a835fe4 into apache:master May 24, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working and you are sure it's a bug!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants