NutzCN Logo
问答 NutzWk项目中SysLogAopInterceptor解析el表达式抛空指针
发布于 3012天前 作者 杨俊 2019 次浏览 复制 上一个帖子 下一个帖子
标签:

protected void doLog(String type, InterceptorChain chain, Throwable e) {
String _msg = null;
if (msg.hasKey()) {
Context ctx = Lang.context();
ctx.set("args", chain.getArgs());
ctx.set("return", chain.getReturn());
Context _ctx = Lang.context();
System.out.println("ctx: " + Json.toJson(ctx));
for (String key : msg.keys()) {
System.out.println("key: " + key);
System.out.println("els: " + els);
System.out.println("els.get(key): " + els.get(key));
_ctx.set(key, els.get(key).eval(ctx));
}
_msg = msg.render(_ctx).toString();
} else {
_msg = msg.getOrginalString();
}
long uid = 0;
Object u = SecurityUtils.getSubject().getPrincipal();
if (u != null && u instanceof ManagerInfo) {
ManagerInfo user = (ManagerInfo) u;
uid = user.getId();
}
Syslog sysLog = Syslog.c(type, tag, uid, _msg, source);
if (async) {
sysLogService.async(sysLog);
} else {
sysLogService.sync(sysLog);
}
}

打印信息:
ctx: {
"map" :{
"args" :[{
"id" :"1",
"name" :"2222",
"path" :"eluxue",
"telephone" :"400-xxx-xxxx",
"introduction" :"",
"linkman" :"9527",
"linkPhone" :"18699992222"
}],
"return" :{
"code" :0
}
}
}
key: arg[0]
els: {arg[0]=arg[0]}
els.get(key): arg[0]

问题:els.get(key).eval(ctx) 抛出空指针
java.lang.NullPointerException
at java.lang.reflect.Array.get(Native Method)
at org.nutz.el.opt.object.ArrayOpt.calculate(ArrayOpt.java:35)
at org.nutz.el.opt.object.FetchArrayOpt.calculate(FetchArrayOpt.java:23)
at org.nutz.el.arithmetic.RPN.calculate(RPN.java:55)
at org.nutz.el.arithmetic.RPN.calculate(RPN.java:38)
at org.nutz.el.El.eval(El.java:30)
at net.eluxue.common.service.log.SysLogAopInterceptor.doLog(SysLogAopInterceptor.java:83)
at net.eluxue.common.service.log.SysLogAopInterceptor.filter(SysLogAopInterceptor.java:65)
at org.nutz.aop.InterceptorChain.doChain(InterceptorChain.java:60)
at net.eluxue.modules.controllers.console.AgencyController$$NUTZAOP.editDo(AgencyController.java:1)
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:497)
at org.nutz.mvc.impl.processor.MethodInvokeProcessor.process(MethodInvokeProcessor.java:25)
at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
at org.nutz.mvc.impl.processor.AdaptorProcessor.process(AdaptorProcessor.java:33)
at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
at org.nutz.mvc.impl.processor.ActionFiltersProcessor.process(ActionFiltersProcessor.java:58)
at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
at org.nutz.integration.shiro.NutShiroProcessor.process(NutShiroProcessor.java:51)
at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
at org.nutz.mvc.impl.processor.ModuleProcessor.process(ModuleProcessor.java:123)
at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
at org.nutz.mvc.impl.processor.EncodingProcessor.process(EncodingProcessor.java:27)
at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
at org.nutz.mvc.impl.processor.UpdateRequestAttributesProcessor.process(UpdateRequestAttributesProcessor.java:15)
at org.nutz.mvc.impl.NutActionChain.doChain(NutActionChain.java:44)
at org.nutz.mvc.impl.ActionInvoker.invoke(ActionInvoker.java:67)
at org.nutz.mvc.ActionHandler.handle(ActionHandler.java:31)
at org.nutz.mvc.NutFilter.doFilter(NutFilter.java:196)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449)
at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365)
at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90)
at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83)
at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:383)
at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362)
at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at net.eluxue.common.mvc.filter.XssFilter.doFilter(XssFilter.java:28)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:617)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:668)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1527)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1484)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)

2 回复
key: arg[0]
els: {arg[0]=arg[0]}
els.get(key): arg[0]

参数的引用名是 args , 不是 arg

添加回复
请先登陆
回到顶部