tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alex Cruikshank <a...@epitonic.com>
Subject [PATCH]: log() throws NPE in GenericServlet
Date Thu, 30 Dec 1999 21:54:37 GMT
The log() method in GenericServlet (which is inherited by HttpJspBase) 
throws a NullPointerException when called by a JSP page.  This is due to 
the fact that HttpJspBase's init(config) method does not call the 
super.init(config) method in it's base class.  Since the init(config) 
method is not called in javax.servlet.GenericServlet the private "config" 
variable in that class is left as null.  When GenericServlet's log() method 
tries to get the servlet name from its config object, it throws a NPE.  The 
easy fix is simply to initialize the base class as well as the HttpJspBase.

Index: HttpJspBase.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-tomcat/src/share/org/apache/jasper/runtime/HttpJspBa 
se.java,v
retrieving revision 1.3
diff -u -r1.3 HttpJspBase.java
--- HttpJspBase.java    1999/11/13 00:32:52     1.3
+++ HttpJspBase.java    1999/12/30 21:30:49
@@ -92,6 +92,7 @@
         throws ServletException
      {
          this.config = config;
+        super.init( config );
         jspInit();
      }


The only problem I can see with this fix is that the init(config) method in 
GenericServlet logs an "init" message every time it is called, causing 
clutter in the log.  Also the GenericServlet does not require a non-null 
ServletConfig object, so, when no config object is provided, it shouldn't 
throw a NPE in the log() methods.  I propose the following changes in the 
GenericServlet:

Index: GenericServlet.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-tomcat/src/share/javax/servlet/GenericServlet.java,v
retrieving revision 1.3
diff -u -r1.3 GenericServlet.java
--- GenericServlet.java 1999/11/08 03:21:33     1.3
+++ GenericServlet.java 1999/12/30 21:04:54
@@ -254,7 +254,7 @@

      public void init(ServletConfig config) throws ServletException {
         this.config = config;
-       log("init");
+//     log("init");
         this.init();
      }

@@ -365,6 +365,6 @@
       */

      public String getServletName() {
-        return config.getServletName();
+        return (config != null) ? config.getServletName() : null;
      }
  }

Thanks,
Alex

Mime
View raw message