首页

调试Groovy报错"Cannot invoke method put() on null object"

标签:groovy,调试,NullPointerException,ERROR,invokeMethod     发布时间:2016-06-08   

一、异常描述

最近调试groovy代码报出了"java.lang.NullPointerException: Cannot invoke method put() on null object",直接代码逻辑走不通,具体详情如下

java.lang.NullPointerException: Cannot invoke method put() on null object@b@    at org.codehaus.groovy.runtime.NullObject.invokeMethod(NullObject.java:77)@b@    at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:45)@b@    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:42)@b@    at org.codehaus.groovy.runtime.callsite.NullCallSite.call(NullCallSite.java:32)@b@    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:42)@b@    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)@b@    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:120)@b@    at com.xwood.mgw.post.processor.testPostProcessor.processCommonIcon(script1465349606930229902336.groovy:228)@b@    at com.xwood.mgw.post.processor.testPostProcessor.this$2$processCommonIcon(script1465349606930229902336.groovy)@b@    at com.xwood.mgw.post.processor.testPostProcessor$this$2$processCommonIcon.callCurrent(Unknown Source)@b@    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:46)@b@    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:133)@b@    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:149)@b@    at com.xwood.mgw.post.processor.testPostProcessor.execute(script1465349606930229902336.groovy:115)@b@    at com.xwood.mobilegw.core.service.business.GroovyProcessorWrapper.process(GroovyProcessorWrapper.java:70)@b@    at com.xwood.mobilegw.biz.shared.router.ServiceRouterImpl.processRoute(ServiceRouterImpl.java:58)@b@    at com.xwood.mobilegw.GatewayController.doPost(GatewayController.java:72)@b@    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)@b@    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)@b@    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)@b@    at java.lang.reflect.Method.invoke(Unknown Source)@b@    at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:176)@b@    at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:436)@b@    at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:424)@b@    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:790)@b@    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)@b@    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:669)@b@    at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:585)@b@    at javax.servlet.http.HttpServlet.service(HttpServlet.java:646)@b@    at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)@b@    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)@b@    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)@b@    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)@b@    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)@b@    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)@b@    at com.pingan.mobilegw.web.filter.LoginFilter.doFilter(LoginFilter.java:80)@b@    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)@b@    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)@b@    at com.pingan.mobilegw.web.filter.KeepMamcLoginStatusFilter.doFilter(KeepMamcLoginStatusFilter.java:71)@b@    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)@b@    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)@b@    at com.pingan.mobilegw.web.filter.HandleClientInfoFilter.doFilter(HandleClientInfoFilter.java:125)@b@    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)@b@    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)@b@    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)@b@    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)@b@    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)@b@    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)@b@    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)@b@    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)@b@    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)@b@    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)@b@    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)@b@    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)@b@    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)@b@    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)@b@    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)@b@    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)@b@    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:314)@b@    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)@b@    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)@b@    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)@b@    at java.lang.Thread.run(Unknown Source)

二、解决步骤

找到testPostProcessor文件, 定位到228行,具体代码如下

//L226     JSONObject bufaxObj = p2pAssetObj.getJSONObject("bufaxObj");@b@//L227     addIconUrl(bufaxObj , productsMap, FUND_ICON_LU);@b@//L228     bufaxObj.put("imgUrl", productsMap.get(FUND_ICON_LU));

如上第L228行应该修改如下,造成了空指针异常NullPointerException

//L226     JSONObject bufaxObj = p2pAssetObj.getJSONObject("bufaxObj");@b@//L227     addIconUrl(bufaxObj , productsMap, FUND_ICON_LU);@b@//L228     if(bufaxObj!=null)@b@//L229      bufaxObj.put("imgUrl", productsMap.get(FUND_ICON_LU));
<<热门下载>>