Resolving java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract.. error


I was trying out the code available here – ‘Getting started with Spring MVC’ (http://blog.springsource.com/2011/01/04/green-beans-getting-started-with-spring-mvc/) – today and was facing an irritating error (see below) everytime when I deployed the code. Finally, found the reason and fixed the issue.

Error Stack Trace

java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/validation/Validation

at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
at org.jboss.classloader.spi.base.BaseClassLoader.access$200(BaseClassLoader.java:63)
at org.jboss.classloader.spi.base.BaseClassLoader$2.run(BaseClassLoader.java:546)
at org.jboss.classloader.spi.base.BaseClassLoader$2.run(BaseClassLoader.java:506)
at java.security.AccessController.doPrivileged(Native Method)
at org.jboss.classloader.spi.base.BaseClassLoader.loadClassLocally(BaseClassLoader.java:504)
at org.jboss.classloader.spi.base.BaseClassLoader.loadClassLocally(BaseClassLoader.java:481)
at org.jboss.classloader.spi.base.BaseDelegateLoader.loadClass(BaseDelegateLoader.java:134)
at org.jboss.classloader.spi.filter.FilteredDelegateLoader.loadClass(FilteredDelegateLoader.java:131)
at org.jboss.classloader.spi.base.ClassLoadingTask$ThreadTask.run(ClassLoadingTask.java:452)
at org.jboss.classloader.spi.base.ClassLoaderManager.nextTask(ClassLoaderManager.java:258)
at org.jboss.classloader.spi.base.ClassLoaderManager.process(ClassLoaderManager.java:152)
at org.jboss.classloader.spi.base.BaseClassLoaderDomain.loadClass(BaseClassLoaderDomain.java:259)
at org.jboss.classloader.spi.base.BaseClassLoaderDomain.loadClass(BaseClassLoaderDomain.java:1102)
at org.jboss.classloader.spi.base.BaseClassLoader.loadClassFromDomain(BaseClassLoader.java:772)
at org.jboss.classloader.spi.base.BaseClassLoader.loadClass(BaseClassLoader.java:415)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at org.springframework.validation.beanvalidation.LocalValidatorFactoryBean.afterPropertiesSet(LocalValidatorFactoryBean.java:183)
…..

Reason

I included this dependency in my project, unaware of the fact that it’s just the api and the implementation should be provided by the application server/web container. We need to remove this jar from classpath to solve this error. But this might be required during compilation. Hence, I modified the maven scope to provided, and that way, the JAR was not copied to the generated app WAR , thereby solving my problem.


<dependency>
 <groupId>javax</groupId>
 <artifactId>javaee-api</artifactId>
 <version>6.0</version>
 <scope>provided</scope>
 </dependency>

Sources

http://www.andrejkoelewijn.com/wp/2010/03/04/absent-code-attribute-in-method-that-is-not-native-or-abstract/
http://weblogs.java.net/blog/ludo/archive/2007/01/java_ee_5_apis.html

About these ads

2 comments

  1. [...] When it worked, it reminded me of another issue that I’ve solved already and is already here in this blog:  http://singztechmusings.wordpress.com/2011/04/14/resolving-java-lang-classformaterror-absent-code-at… [...]

  2. It worked, i had the same configuration. thank you.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 26 other followers

%d bloggers like this: