vikifor
vikifor

Reputation: 3466

Class ClassFormatError :Absent-Code-attribute-in-method-that-is-not-native

I have JSP project run on tomcat 6.0.32 and java 6, that suddenly threw this exception

java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file com/company/secure/Account
java.lang.ClassLoader.defineClass1(Native Method)
java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
java.lang.ClassLoader.defineClass(ClassLoader.java:615)
java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2818)
org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1159)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1647)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1526)
org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:128)
org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:66)
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:150)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:338)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
filters.ObjectsCacheFilter.doFilter(ObjectsCacheFilter.java:43)
filters.FilterCach.doFilter(FilterCach.java:81)
filters.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:123)

note The full stack trace of the root cause is available in the Apache Tomcat/6.0.32 logs. Apache Tomcat/6.0.32

Upvotes: 0

Views: 3818

Answers (1)

Stephen C
Stephen C

Reputation: 718886

The problem is due to your webapp (in this case the JSP framework) attempting to load classes from an API-only JAR file.

Here is another example of the problem (though possibly for a different Java EE API):

Explanation: some of the Java EE APIs are available in two forms; i.e. 2 distinct JAR files:

  • The platform-specific form has code for all of the methods. This JAR is typically part of the web container, and is included in every web-apps effective classpath by default.

  • The API-only form has methods that have had their executable code stripped out. This JAR is provided by Oracle to allow you to compile your Java EE application code independently of any specific Java EE implementation.

The problem is most likely that you have put one of these API-only JARs onto the runtime classpath of your webapp, and it is taking precedence over the platform-specific JAR.

Given that this has "happened suddenly", I suspect that you have been changing the Maven dependencies for your project, and (accidentally) made an API-only JAR file a runtime dependency rather than a compile-time-only dependency.

Solution: Check your webapp's Maven (etc) dependencies, or if you are managing the dependencies by hand, check what JARs you have put into the webapp's WEB-INFO/lib directory and the web container's shared libraries directory.

Upvotes: 3

Related Questions