documentation home

FAQ  Build fails with java.lang.ClassFormatError: Absent Code attribute in method ...


Problem

The maven build fails with this (or a similar) error.

[ERROR] Failed to execute goal com.qmino:miredot-plugin:<version>:restdoc (default) on project <name>: Execution default of goal com.qmino:miredot-plugin:<version>:restdoc failed: An API incompatibility was encountered while executing com.qmino:miredot-plugin:<name>:restdoc: java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file <classpath>

Solution

This issue occurs when you depend on java libraries containing invalid classes (explanation, see below). Unfortunately, this is the case for some official j2ee API jars. You probably had one of these dependencies in your pom.

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

Basically, Oracle just stripped the method bodies of all the methods, resulting in invalid classes (not cool!) since this is not allowed for non-native, non-abstract methods. This causes problems, not only with Miredot, but with every tool that uses reflection to do its job, including a number of Netbeans and/or Eclipse plugins as well.

This issue can be solved by including an implementation of the methods. You can for example include the glassfish implementation such as shown below. Any other implementation will work as well. By setting the scope to provided, this will not influence your generated jar or war.

<dependency>
    <groupId>org.glassfish.main.extras</groupId>
    <artifactId>javaee</artifactId>
    <version>3.0.1</version>
    <scope>provided</scope>
</dependency>

Here are some additional references if you're interested: https://community.jboss.org/wiki/WhatsTheCauseOfThisExceptionJavalangClassFormatErrorAbsentCode http://www.mkyong.com/hibernate/java-lang-classformaterror-absent-code-attribute-in-method-that-is-not-native-or-abstract-in-class-file/