Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NullPointerException for javax.servlet.GenericServlet.getServletContext(GenericServlet.java:205)

Tags:

struts-1

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??

like image 681
Kunal Jha Avatar asked Apr 13 '26 16:04

Kunal Jha


1 Answers

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.

like image 60
BalusC Avatar answered Apr 19 '26 18:04

BalusC



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!