Oh noooooes! javax.el.ELException: [class] is not a valid Java identifier on Apache Tomcat 7

org.apache.el.parser.SKIP_IDENTIFIER_CHECK default changed from true to false.

I recently moved my Pebble 2.3.1 blog from one machine to another. In the process of doing so a couple of things broke, like comment validation. Trying to review and approve comments resulted in a mostly blank screen.

A check of the logs gave me my first clue:

Mar 22, 2011 2:24:37 PM org.apache.catalina.core.ApplicationDispatcher invoke
SEVERE: Servlet.service() for servlet jsp threw exception
org.apache.jasper.JasperException: /WEB-INF/jsp/viewResponses.jsp(65,0) "${response.class.name == 'pebble.blog.Comment'}" 
contains invalid expression(s): javax.el.ELException: [class] is not a valid Java identifier
	at org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40)
	at org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407)
	at org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:198)
 {snip}

My Google searches quickly lead me believe other people, not all of them Pebble users, were having a similar issue. And folks were blaming the more recent releases of Apache Tomcat. As it turns out, the Tomcat developers changed the default value for org.apache.el.parser.SKIP_IDENTIFIER_CHECK from true to false. What it does is tell the JVM that identifiers should not be checked to ensure that they conform to the Java Language Specification for Java identifiers. This was done to more closely comply with the JLS. Unfortunately, it has lead to many JSP-based webapps breaking.

With Pebble, the problem was the use of JLS reserved keywords for identifies. In the below snipped from WEB-INF/jsp/viewResponses.jsp, Pebble uses the reserved word “class”.

  <c:if test="${response.class.name == 'pebble.blog.Comment'}">

If you are a developer of a webapp that is experiencing this issue, it is best if you just work through the problems and change your app. If you are a plain old users like me, try upgrading…or adding this system property to your Tomcat startup script. (E.g.: {tomcat-home}/bin/startup.sh) and restart.

JAVA_OPTS="$JAVA_OPTS -Dorg.apache.el.parser.SKIP_IDENTIFIER_CHECK=true" 
export JAVA_OPTS

And presto! Problem solved. Hopefully. For now. Until it breaks again. Because this is a workaround, not a solution.