Lab Notes

Things I want to remember how to do.

Absent Code

September 3, 2012

I recently hit an error I had never seen before:

Caused by: java.lang.ClassFormatError: Absent Code attribute in method that is
not native or abstract in class file javax/servlet/http/HttpCookie

A little research and I discovered that some versions of the javaee.jar contain essentially just the method signatures without any bodies. This is fine for compiling against but can cause issues when running JUnit, i.e. unit tests.

The solution turned out to be to use a JEE jar from an application server. I use JBoss, but they seemed to have the jar scattered all over the place so I turned to GlassFish. GlassFish didn’t exactly give me one-stop shopping either but it was easier to put together the implementation jar than with JBoss.

If you don’t need the jar in any particular place you can just add it to your classpath. Otherwise if you are moving it, note that the jar itself contains nothing but a manifest pointing to other jars. Make sure you copy the other jars and preserve the directory structure.

Big hat tip to mkyong at http://www.mkyong.com/ who did the leg work for me on this one:

http://www.mkyong.com/hibernate/java-lang-classformaterror-absent-code-attribute-in-method-that-is-not-native-or-abstract-in-class-file/