Awkward bug in Tomcat 6.0.41 - NoSuchElementException on empty attribute
Posted by jchocholacek Nov 29, 2014Just shortly today: we have hit an awkward bug in Tomcat 6.0.41 this week (is present also in 7.x and 8.x Tomcat line). When you have a JSP page that includes another JSP file, which contains an element with empty attribute, e.g. <input name="xy" value="" />, then an attempt to display such page leads to an error and a "funny" message in the log file:
SEVERE: Servlet.service() for servlet jsp threw exception
java.util.NoSuchElementException
at java.util.AbstractList$Itr.next(AbstractList.java:350)
at org.apache.jasper.compiler.Validator$ValidateVisitor.getJspAttribute(Validator.java:1330)
at org.apache.jasper.compiler.Validator$ValidateVisitor.visit(Validator.java:737)
at org.apache.jasper.compiler.Node$UninterpretedTag.accept(Node.java:1246)
at org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2361)
...
at org.apache.taglibs.standard.tag.common.core.ImportSupport.acquireString(ImportSupport.java:296)
at org.apache.taglibs.standard.tag.common.core.ImportSupport.doEndTag(ImportSupport.java:161)
at org.apache.jsp.yourpage_jsp._jspx_meth_c_005fimport_005f6(yourpage_jsp.java:713)
...
I have tracked it down to https://issues.apache.org/bugzilla/show_bug.cgi?id=56561 and https://issues.apache.org/bugzilla/show_bug.cgi?id=56610, but my problem was, that our hosting provider runs Debian, and there is no tomcat6 package for Debian with the newest 6.0.43 version. So I had to apply the following workaround to my JSP files (luckily, there was just few of them):
<c:set var="EMPTY_STRING" value="" />
...
<input name="xy" value="${EMPTY_STRING}" />
Anyway, if you are hitting this bug, too, then the best option is to upgrade your Tomcat version, if possible.