Return-Path: Mailing-List: contact tomcat-dev-help@jakarta.apache.org; run by ezmlm Delivered-To: mailing list tomcat-dev@jakarta.apache.org Received: (qmail 78135 invoked from network); 30 Dec 1999 21:49:43 -0000 Received: from unknown (HELO web1.epitonic.com) (216.33.145.58) by 63.211.145.10 with SMTP; 30 Dec 1999 21:49:43 -0000 Received: from bmovie (adsl-216-102-219-194.dsl.snfc21.pacbell.net [216.102.219.194]) by web1.epitonic.com (8.8.8+Sun/8.8.8) with ESMTP id NAA16983 for ; Thu, 30 Dec 1999 13:45:50 -0800 (PST) Message-Id: <4.2.0.58.19991230133229.00bb05b0@pop.epitonic.com> X-Sender: alex@pop.epitonic.com X-Mailer: QUALCOMM Windows Eudora Pro Version 4.2.0.58 Date: Thu, 30 Dec 1999 13:54:37 -0800 To: tomcat-dev@jakarta.apache.org From: Alex Cruikshank Subject: [PATCH]: log() throws NPE in GenericServlet Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed 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