最近运行别人项目的时候,java.lang.NullPointerException 但是看了半天也不知道那个地方空指针了

问题描述

Struts Problem ReportStruts has detected an unhandled exception:Messages: File: com/lingx/system/security/SecurityContextFactory.javaLine number: 28Stacktracesjava.lang.NullPointerException com.lingx.system.security.SecurityContextFactory.getUserDetails(SecurityContextFactory.java:28) com.lingx.system.security.SecurityContextFactory.getUser(SecurityContextFactory.java:48) com.lingx.loas.utils.OperationLogger.record(OperationLogger.java:41) sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) java.lang.reflect.Method.invoke(Method.java:597) org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:627) org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:609) org.springframework.aop.aspectj.AspectJAfterAdvice.invoke(AspectJAfterAdvice.java:45) org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171) org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89) org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171) org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:635) com.lingx.loas.web.IndexAction$$EnhancerByCGLIB$$af3cdece.execute() sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) java.lang.reflect.Method.invoke(Method.java:597) com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:440) com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:279) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242) com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:163) com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:249) org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68) com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:122) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:195) com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:195) com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:148) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:93) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:235) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:89) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:126) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:138) com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:195) com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:148) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:128) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:176) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) org.apache.struts2.interceptor.MessageStoreInterceptor.intercept(MessageStoreInterceptor.java:204) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:52) org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:468) org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77) org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:76) org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198) org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76) org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:96) org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76) org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225) org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169) org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472) org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168) org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98) org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927) org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407) org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:999) org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:565) org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:307) java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895) java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918) java.lang.Thread.run(Thread.java:662)

解决方案

SecurityContextHolder这个应该属于springsecurity的类吧。也就是说你们应该继承了springsecurity安全组件。首先说下这个问题为什么会发生。1 首先,SpringSecurity的保存用户信息(登陆session)他并非是保存在httpsession中的,而是保存在本地线程中的。也就是说,其实如果你直接通过session。get方法是无法拿去到你登陆后的session信息,即你中间所说的Authentication对象。所以依据这种情况,SpringSecurity提供了两种方式来帮助你获取到你验证后的用户信息,2 第一种是通过SecurityContextHolder.getContext().getAuthentication()这种方式, 另外还有一个方式是你直接在httpsession中拿去对应的authentication对象,这个关键字设置为专门的值的,如果我没记错的话,关键字应该是:HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY.3 关于你这个原因产生,我猜测是由于你们在springsecurity验证完成后没有吧对应的security放入到session中导致,所以你拿去的Authentication为空,自然就是会报控制正了,建议你查看下你们自己写的springSecurity验证类。这个类应该是实现了接口UserDetailsService,这个实现类有几个用途,其一就是实现身份验证,就是验证用户名密码是否正确,另外一个就是需要把验证后的authencation对象放入到session中,你没有放,那么你肯定是无法获取到的。而方式SecurityContextHolder.getContext().getAuthentication()不为空的前提就是你在这个类的验证完成后需要调用方法SecurityContextHolder.getContext().setAuthentication(). 建议你查询下这个类是否有问题。
解决方案二:
第28行。 你应该让eclipse显示行号。或者鼠标点击括号中的内容,将直接跳到报错代码处。com.lingx.system.security.SecurityContextFactory.getUserDetails(SecurityContextFactory.java:28) 你可以分析那行代码,你也可以把那行代码贴出来看看。

时间: 2024-11-02 07:28:35

最近运行别人项目的时候,java.lang.NullPointerException 但是看了半天也不知道那个地方空指针了的相关文章

java web-Java web项目java.lang.NullPointerException

问题描述 Java web项目java.lang.NullPointerException java.io.IOException: Cannot run program "jad" (in directory "C:UsersAdministrator.net.sf.jadclipse1456277127516"): CreateProcess error=2, 系统找不到指定的文件. 解决方案 文件不存在,你看看路径对不对 解决方案二: 估计是路径的问题吧,,

不知道为什么,每次在WTK自带的KToolbar新建J2ME项目时,总是弹出“不能产生项目XX,java.lang.NullPointerException"

问题描述 不知道为什么,每次在WTK自带的KToolbar新建J2ME项目时,总是弹出"不能产生项目XX,java.lang.NullPointerException"那位达人知道怎么回事啊?小弟在线等!被这个问题弄了n久了...(apps里其他项目可以正常运行) 解决方案 解决方案二:KToolbar解决方案三:空指针异常,是程序写的不对,怪不得别人解决方案四:什么程序,请详细一点解决方案五:哦,是我没看清,这个情况我没遇到过,我用的是eclipse,帮顶

web 环境项目(intellj部署的tomcat) 重启时报 Exception in thread "HouseKeeper" java.lang.NullPointerException (转)

Exception in thread "HouseKeeper" java.lang.NullPointerException at org.logicalcobwebs.proxool.HouseKeeperController.getHouseKeeperToRun(HouseKeeperController.java:52) at org.logicalcobwebs.proxool.HouseKeeperThread.run(HouseKeeperThread.java:33

ssh-学习用MyEclipse 2013开发SSH项目遇到java.lang.NullPointerException问题,请帮助!

问题描述 学习用MyEclipse 2013开发SSH项目遇到java.lang.NullPointerException问题,请帮助! SaveOfficeAction.java出错:java.lang.NullPointerException package we.app.action; import we.app.data.*; import com.opensymphony.xwork2.ActionSupport; public class SaveOfficeAction exten

java web java.lang.NullPointerException

问题描述 java web java.lang.NullPointerException 严重: Servlet.service() for servlet [selectServlet] in context with path [/Exercise] threw exceptionjava.lang.NullPointerException at DB.DataBaseConnection.selectOperation1(DataBaseConnection.java:45) at Ser

ndroid-新人求助 java.lang.NullPointerException

问题描述 新人求助 java.lang.NullPointerException 04-26 21:42:40.039: E/AndroidRuntime(1125): FATAL EXCEPTION: main 04-26 21:42:40.039: E/AndroidRuntime(1125): Process: com.example.remotecontrol, PID: 1125 04-26 21:42:40.039: E/AndroidRuntime(1125): java.lang

二维数组-java报错thread "main" java.lang.NullPointerException

问题描述 java报错thread "main" java.lang.NullPointerException import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; import java.util.Scanner; public class exercise { /** * @param args */ public stat

socket-多线程 java.lang.NullPointerException

问题描述 多线程 java.lang.NullPointerException Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at javax.swing.plaf.basic.BasicListUI.paintImpl(BasicListUI.java:266) at javax.swing.plaf.basic.BasicListUI.paint(BasicListUI.java:240)

请高手帮忙,为什么提示java.lang.NullPointerException这个错误

问题描述 if(request.getParameter("title")!=null){sql="insertintonewsvalues("+currid;sql+=",'"+title+"','"+content+"',";sql+="date(),'"+keywords+"','"+author+"')";conn.executeQuery