java.lang.ClassFormatError: Absent Code attribute
October 22, 2011 19:51:05 Last update: October 22, 2011 20:31:48
I built a very basic JSF application and deployed to Tomcat 7.0.22, but it failed with this error:
That looks weird and I wasn't able to find a sensible explanation!
So I copied the
I also copied
But when I replaced the
Conclusions:
Caused by: java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/faces/webapp/FacesServlet at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631) at java.lang.ClassLoader.defineClass(ClassLoader.java:615) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141) at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2820)
That looks weird and I wasn't able to find a sensible explanation!
So I copied the
jsf-api-2.1.jar, which was downloaded from the java.net Maven repository by Maven, into a temp folder. And tested it with this simple program:
public class ClassFormatErrorTest { public static void main(String[] args) throws Exception { Class.forName("javax.faces.webapp.FacesServlet"); } }
I also copied
servlet-api.jar from Tomcat's lib folder to the temp folder. Sure enough it failed with the same error:
C:\tmp>java -cp .;jsf-api-2.1.jar;servlet-api.jar ClassFormatErrorTest
Exception in thread "main" java.lang.ClassFormatError: Absent Code attribute in
method that is not native or abstract in class file javax/faces/webapp/FacesServlet
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at ClassFormatErrorTest.main(ClassFormatErrorTest.java:3)
But when I replaced the
javax.faces.webapp.FacesServlet class with one I compiled from source, the error disappears!
Conclusions:
- The jar file
jsf-api-2.1.jarfrom java.net Maven repository is good for compilation only (cannot be used at runtime). Thejavax.faces.webapp.FacesServletclass inside it is just an empty shell without code. - The class is not generated by normal Java compilation with javac.
- How to generate an "empty shell" class file remains a mystery to me!