You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by Tom Rodriguez <tr...@parc.xerox.com> on 1999/11/22 20:53:01 UTC

PATCH: jakarta-tomcat/src/share/org/apache/jasper/runtime/JspLoader.java

This is a fix for some small problems with the JspLoader.  These are
both unusual cases but I wasted a lot of time tracking down the root
cause and I don't think anyone else should have too.

The first part is actually a workaround for a bug in both the Classic
and HotSpot VMs for 1.2.  If you pass null to
ClassLoader.findLoadedClass the VM crashes because it isn't properly
checking for it.  This is fixed in an internal release of 1.3, i.e. not
1.3beta but it's kind of scary to see the crash, so i though it'd be
nicer to get catch it here.  Various bogus situations cause JspLoader to
pass null into loadClass and I didn't understand how to debug those. 
You can probably reproduce the problem by deleting the generated JSP
classfiles underneath a running tomcat server.

The second part is a sanity check for the case where somehow JSP
classfiles end up somewhere else on your classpath than the work
directory and get loaded from there instead of from the newly generated
classfile.  In this case the classloader for the resulting class won't
be the JspLoader itself so I just check for that.

tom

Index: src/share/org/apache/jasper/runtime/JspLoader.java
===================================================================
RCS file:
/home/cvspublic/jakarta-tomcat/src/share/org/apache/jasper/runtime/JspLoader.java,v
retrieving revision 1.2
diff -c -r1.2 JspLoader.java
*** JspLoader.java	1999/10/21 01:48:42	1.2
--- JspLoader.java	1999/11/22 19:40:30
***************
*** 124,129 ****
--- 124,133 ----
      protected synchronized Class loadClass(String name, boolean
resolve)
  	throws ClassNotFoundException
      {
+ 	if (name == null) {
+ 	    throw new ClassNotFoundException("null is not a valid class
name");
+ 	}
+ 
  	// First, check if the class has already been loaded
  	Class c = findLoadedClass(name);
  	if (c == null) {
***************
*** 237,242 ****
--- 241,249 ----
  	if((jspClass == null) || outDated) {
  	    try {
  		jspClass = loadClass(ctxt.getFullClassName(), true);
+ 		if (jspClass.getClassLoader() != this) {
+ 		    throw new JasperException("somehow loaded class from normal
class path");
+ 		}
  	    } catch (ClassNotFoundException cex) {
  		throw new
JasperException(Constants.getString("jsp.error.unable.load"), 
  					  cex);