Question

When I deployed a maven 3.0.3 built webapp into tomcat 7.0.23 on Linux (java 1.6.x) and accessed posted my credentials in the login page, I got the following error. pom.xml references servlet 2.5, jsp 2.1 and JSTL 1.2.

Why would I get this Error ? what can I do to avoid it ?

I have other .war files deployed on the same tomcat instance and never faced this issue in those apps.

The 1st JSP(login.jsp) that I did a http GET didn't throw an error. The POST from the 1st JSP to the 2nd Jsp(ChLogin.jsp) encountered the problem.

===========================

root cause

java.lang.VerifyError: (class: org/apache/jsp/ChLogin_jsp, method: _jspService signature: (Ljavax/servlet/http/HttpServletRequest;Ljavax/servlet/http/HttpServletResponse;)V) Inconsistent stack height 0 != 1
    java.lang.Class.getDeclaredConstructors0(Native Method)
    java.lang.Class.privateGetDeclaredConstructors(Class.java:2389)
    java.lang.Class.getConstructor0(Class.java:2699)
    java.lang.Class.newInstance0(Class.java:326)
    java.lang.Class.newInstance(Class.java:308)
    org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:172)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:369)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

UPDATE 1
the WEB-INF\lib of the webapp does NOT contain servlet, jsp or JSTL jars. It contains many application dependencies and spring jars (we use spring MVC).

UPDATE 2
We don't pre-compile JSPs. That is a goal for another day, though.

UPDATE 3
Discovered that this problem was not in tomcat 7.0.12, 7.0.14, 7.0.16 but started with 7.0.19. Posted to tomcat users mailing list. got a reply that it was perhaps the eclipse JDT compiler at fault. Verified that is indeed the case by replacing the compiler in tomcat 7.0.23/27 with tomcat 7.0.16's JDT compiler and LO & BEHOLD, all is well. I am planning to write to the Eclipse JDT compiler team(if there is one) and post about this error.

Was it helpful?

Solution

The error is quite obvious: there is a bug in the jasper creating the bytecode. The generated code doesn't clear the stack frame propery Inconsistent stack height 0 != 1

You may try to shuffle the code, split into methods, move lines here and there and the bug might go away. Also can you post relevant info of the jsp servlet (matching *.jsp) from web.xml (usually somewhere in conf) to check compiler parameters?

OTHER TIPS

This error means the JSP has been compiled for a specific Servlet/JSP/JSTL implementation but then Tomcat tries to load compiled classes with an other implementation/version available in ClassPath.

It probably happens because your WAR contains jar files with servlet, jsp and/or jstl API and/or implementation. As used versions match Tomcat 5.5 imlementation, it works there but fail with more recent implementations.

You have to set the scope to provided for such dependencies in your Maven POM to exclude that jars from WAR WEB-INF/lib.

To validate that on-the-fly compiled code does not load alternate dependencies, you should run Tomcat with -verbose:class. Latest lines before the error may help to guess what is wrong.

Update 2012/05/30 Do you have any jasper or javax.el or el-api jar in WEB-INF/lib ? If so, remove it/them as well.

It is also possible that a taglib you used is specifically compiled for Tomcat 5.5 Servlet 2.3 API and breaks when Tomcat 7.

Have you tried disabling the Split Verifier: -XX:-UseSplitVerifier

Here is a reference for JVM options: http://www.oracle.com/technetwork/java/javase/tech/vmoptions-jsp-140102.html

I have seen something similar with Java 7 and the VerifyError.

Try printing the classpath (System.out.println("java.class.path");) Compare the classpath of the tomcat5 and tomcat7. Check what is the difference in the classpath.

This happened with me on Tomcat 6.0.35 and just in one jsp page, which has only:

<jsp:forward page="/sindicato/consultaServidor.jsp"/>

The solution was replace the jsp tag by jstl tag:

<c:redirect url="/sindicato/consultaServidor.jsp"/>

And don't ask why! Because we have more jsp pages with that jsp tag (jsp:forward) with no problem.

java.lang.VerifyError:

Easy W/A

This is because of the built in tomcat compiler.

The Java compiler from Eclipse JDT in included as the default compiler. It is an advanced Java compiler which will load all dependencies from the Tomcat class loader, which will help tremendously when compiling on large installations with tens of JARs. On fast servers, this will allow sub-second recompilation cycles for even large JSP pages.

If any such issues is seen follow the below workaround

Apache Ant, which was used in previous Tomcat releases, can be used instead of the new compiler by simply removing the lib/ecj-*.jar file, and placing the ant.jar and ant-launcher.jar files from the latest Ant distribution in the lib folder.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top