NullPointerException for javax.servlet.GenericServlet.getServletContext(GenericServlet.java:205)
I am running a Weblogic 8.1 SP6 server (JDK 1.4.2) on the production system.Now and then we get the below exception on the production server before the server goes down. I have absolutely no clue on how approach this problem.
java.lang.NullPointerException
at javax.servlet.GenericServlet.getServletContext(GenericServlet.java:205)
at com.sampleapp.arch.struts.InitializingRequestProcessor.getProcessorForModule(InitializingRequestProcessor.java:135)
at com.sampleapp.arch.struts.InitializingRequestProcessor.initializeFormBean(InitializingRequestProcessor.java:29)
at com.sampleapp.arch.struts.ResettingDynaValidatorForm.reset(ResettingDynaValidatorForm.java:46)
at org.apache.struts.taglib.html.FormTag.initFormBean(FormTag.java:484)
at org.apache.struts.taglib.html.FormTag.doStartTag(FormTag.java:457)
at org.apache.strutsel.taglib.html.ELFormTag.doStartTag(ELFormTag.java:267)
at jsp_servlet._util.__settingsdisplay_f._jspService(__settingsdisplay_f.java:355)
at weblogic.servlet.jsp.JspBase.service(JspBase.java:33)
The code snippet for the InitializingRequestProcessor is given below and the NullPointerException is thrown on the return statement.
Please ask if you need any other information. Thanks in advance.
private static RequestProcessor getProcessorForModule(ActionServlet servlet, ModuleConfig config) {
String key = Globals.REQUEST_PROCESSOR_KEY + config.getPrefix();
return (RequestProcessor) servlet.getServletContext().getAttribute(key);
}
Update
开发者_运维百科 Based on the response from Alex it turns out that ResettingDynaValidatorForm (custom implemetation of DynaValidatorForm) is getting the super ActionServlet from the ActionForm class of struts which is returning NULL value. Is there a reason why the server will start returning NULL values for ActionServlet only after running for few days??This look much like a bug in Struts. This NPE is typical for ServletConfig
being absent, which means that the servlet in question didn't override the init(ServletConfig config)
method properly. As per the linked javadoc, the implementor has to explicitly call super.init(config)
in there. If you don't do this, you will get this kind of NPE.
Try upgrading Struts.
Is InitializingRequestProcessor your own class ?
Is is extending RequestProcessor ? Is it possible your are overriding a method (something like init) and not calling super.init in it ?
From what I can see, it looks like the ActionServlet was not set the ServletContext. It could happen if one of your class extends one of the Struts framework's class. Make sure you call super.methodName in methods you override from Struts Framework such as ActionServlet or RequestProcessor...
Good luck, let us know how it goes
精彩评论