JSP fails due to java.lang.ClassFormatError: Truncated class file

Solution Unverified - Updated -

Environment

  • JBoss Enterprise Application Platform (EAP) 6.x

Issue

  • We see an error like the following when requesting a JSP:
JBWEB000236: Servlet.service() for servlet jsp threw exception: java.lang.ClassFormatError: Truncated class file
    at java.lang.ClassLoader.defineClass1(Native Method) [rt.jar:1.7.0_55]
    at java.lang.ClassLoader.defineClass(ClassLoader.java:800) [rt.jar:1.7.0_55]
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) [rt.jar:1.7.0_55]
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:449) [rt.jar:1.7.0_55]
    at java.net.URLClassLoader.access$100(URLClassLoader.java:71) [rt.jar:1.7.0_55]
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361) [rt.jar:1.7.0_55]
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355) [rt.jar:1.7.0_55]
    at java.security.AccessController.doPrivileged(Native Method) [rt.jar:1.7.0_55]
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354) [rt.jar:1.7.0_55]
    at org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:137) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1]
    at org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:69) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1]
    at org.jboss.as.web.deployment.WebInjectionContainer.newInstance(WebInjectionContainer.java:97) [jboss-as-web-7.3.0.Final-redhat-14.jar:7.3.0.Final-redhat-14]
    at org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:142) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1]
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:320) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1]

Resolution

  • Stop JBoss, clear its tmp directory, and restart to correct the error

Root Cause

  • A bad JSP class file was compiled or something outside of JBoss modified and corrupted the class

Diagnostic Steps

Capture the following for review of what introduces the bad JSP class:
* JBoss server logs, produced with the following debug logging enabled in your logging subsystem:

        <logger category="org.apache.jasper.compiler">
            <level name="DEBUG"/>
        </logger>
  • JBoss access logging. Enable it like so by adding an access-log with a pattern like below to the virtual server(s) in your web subsystem:

    <subsystem xmlns="urn:jboss:domain:web:1.1" default-virtual-server="default-host" native="false">
        <connector name="http" protocol="HTTP/1.1" scheme="http" socket-binding="http"/>
        <virtual-server name="default-host" enable-welcome-root="true">
           <access-log pattern="%T %h %l %A %v %t %r %s %b %S %I"/>
    
  • Compress and preserve the JBoss tmp directory at the time of the issue.

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

Comments