tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Hume, John - NA US HQ Delray" <john.h...@cruisesonly.com>
Subject RE: Tomcat 5 - jsp:useBean causing a compile time exception (not pilot error - long detailed post)
Date Tue, 20 Jan 2004 18:18:48 GMT
I believe you can change class="..." to type="..." to indicate that that's
the type of the reference but not a class that Jasper should attempt to
instantiate.

-john.


-----Original Message-----
From: Andrew Schwimmer [mailto:andrew@omnipod.com]
Sent: Tuesday, January 20, 2004 12:16 PM
To: Tomcat Users List
Subject: Tomcat 5 - jsp:useBean causing a compile time exception (not
pilot error - long detailed post)


Summary:
Code that worked in Tomcat4 throws a compile time exception in Tomcat5.


My Jsp file consists of one line.
<jsp:useBean scope="request" id="l" class="java.util.List"/>

In Tomcat 4 a line like this was legal. If "l" did not exist in the request
scope it would try to instantiate it and throw a runtime
java.lang.InstantiationException. However in Tomcat 5 it causes this compile
time exception.

org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: 1 in the jsp file: /useBeanTest.jsp

Generated servlet error:
    [javac] Compiling 1 source file

C:\jakarta-tomcat-5.0.16\work\Catalina\localhost\jsp-examples\org\apache\jsp
\useBeanTest_jsp.java:44: java.util.List is abstract; cannot be instantiated
          l = new java.util.List();
              ^
1 error



org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandle
r.java:127)

org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:3
51)
	org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:415)
	org.apache.jasper.compiler.Compiler.compile(Compiler.java:458)
	org.apache.jasper.compiler.Compiler.compile(Compiler.java:439)

org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:5
52)

org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:2
91)
	
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:853)

The  code generated in Tomcat5 is

      java.util.List l = null;
      synchronized (request) {
        l = (java.util.List) pageContext.getAttribute("l",
PageContext.REQUEST_SCOPE);
        if (l == null){
          l = new java.util.List();
          pageContext.setAttribute("l", l, PageContext.REQUEST_SCOPE);
        }
      }

The code generated in Tomcat4 is

      java.util.List l = null;
      synchronized (request) {
        l = (java.util.List) pageContext.getAttribute("l",
PageContext.REQUEST_SCOPE);
        if (l == null){
          try {
            l = (java.util.List)
java.beans.Beans.instantiate(this.getClass().getClassLoader(),
"java.util.List");
          } catch (ClassNotFoundException exc) {
            throw new InstantiationException(exc.getMessage());
          } catch (Exception exc) {
            throw new ServletException("Cannot create bean of class " +
"java.util.List", exc);
          }
          pageContext.setAttribute("l", l, PageContext.REQUEST_SCOPE);
        }
      }


Which throws the exception because you aren't allowed to instantiate an
abstract class.

--------------------------------------------------------------------

A similar exception is being thrown if you attempt to retrieve an array.

A line in a jsp...
<jsp:useBean scope="request" id="l" class="java.util.ArrayList[]"/>

Yields an exception...

org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: 1 in the jsp file: /useBeanTest2.jsp

Generated servlet error:
    [javac] Compiling 1 source file

C:\jakarta-tomcat-5.0.16\work\Catalina\localhost\jsp-examples\org\apache\jsp
\useBeanTest2_jsp.java:44: array dimension missing
          l = new java.util.ArrayList[]();
                                       ^
1 error



org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandle
r.java:127)

org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:3
51)
	org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:415)
	org.apache.jasper.compiler.Compiler.compile(Compiler.java:458)
	org.apache.jasper.compiler.Compiler.compile(Compiler.java:439)

org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:5
52)

org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:2
91)
	
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:853)

In this case the code generated in Tomcat5 is
      java.util.ArrayList[] l = null;
      synchronized (request) {
        l = (java.util.ArrayList[]) pageContext.getAttribute("l",
PageContext.REQUEST_SCOPE);
        if (l == null){
          l = new java.util.ArrayList[]();
          pageContext.setAttribute("l", l, PageContext.REQUEST_SCOPE);
        }
      }

The code generated in Tomcat4 is

      java.util.ArrayList[] l = null;
      synchronized (request) {
        l = (java.util.ArrayList[]) pageContext.getAttribute("l",
PageContext.REQUEST_SCOPE);
        if (l == null){
          try {
            l = (java.util.ArrayList[])
java.beans.Beans.instantiate(this.getClass().getClassLoader(),
"java.util.ArrayList[]");
          } catch (ClassNotFoundException exc) {
            throw new InstantiationException(exc.getMessage());
          } catch (Exception exc) {
            throw new ServletException("Cannot create bean of class " +
"java.util.ArrayList[]", exc);
          }
          pageContext.setAttribute("l", l, PageContext.REQUEST_SCOPE);
        }
      }


If this should be in the Tomcat-Dev list, I'm sorry and I'll move it there.
If this has already been brought up as I bug in Tomcat5, sorry for bringing
it up again but I couldn't find any mention of it in Bugzilla.

Thanks for reading.

-Andrew.



---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Mime
View raw message