tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From KUROSAKA Teruhiko <>
Subject ForEach implementation lacks the final else clause, and some general suggestion
Date Sat, 12 Jun 2004 21:21:06 GMT
I am using tomcat 5.0.25 and it seems that forEach tag
is implemented to generate an if-else chain when it is given
an "items" parameter.  The chain looks like this:
   if (_jspx_temp16 instanceof Object[])
   else if (_jspx_temp16 instanceof boolean[])
   else if (_jspx_temp16 instanceof Enumeration)
   else if (_jspx_temp16 instanceof Map)

   while (_jspx_temp17.hasNext()){...}

This lacks the final catch-all "else" clause.
Because of this, if the items has a class object
that cannot be handled by the forEach implementation,
the temporary variable (_jspx_temp17 in this case)
remains null and attempting to invoke hasNext() on it
in the following while condition causes a generic

For example, the following
tag expression causes this situation:
	<c:forEach var='x' items='${servletContext}'>

When this happens, it is very hard to debug for non-Java
programmers which EL and JSTL is trying to address,
HTML authors without Java knowledge.
One has to read the translated Java file and understand
the relationship between the .jsp and .java file.

Perhaps the better way to handle this case is to have
the final "else" clause in which a JspTagException is thrown?
		throw new JspTagException(
"The \"items\" attribute is given an object that cannot be iterated.");

I supposed this can be done relatively easily by inserting
another call to	ctxt.generateJavaSource("else throw....");

More ideally, the exception message should include
the offending .jsp file name and the line number information
so that the JSP authoer can easily identify the offending
line, but I am not sure if it can be done easily under the
current implementation framework.

KUROSAKA ("Kuro") Teruhiko
San Francisco, California, USA

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message