ClassFormatError

347 views
Skip to first unread message

lex...@gmail.com

unread,
Jun 16, 2014, 4:23:56 PM6/16/14
to cdi-...@googlegroups.com
Hello,

I am trying CDI-Unit for the first time and I am getting this error:
 
java.lang.Exception: There were class format errors. This is often caused by API only jars on the classpath. If you are using maven then you need to place these after the CDI unit dependency as 'provided' scope is still available during testing.
at org.jglue.cdiunit.CdiRunner.createTest(CdiRunner.java:102)
at org.junit.runners.BlockJUnit4ClassRunner$1.runReflectiveCall(BlockJUnit4ClassRunner.java:244)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.BlockJUnit4ClassRunner.methodBlock(BlockJUnit4ClassRunner.java:241)
at org.jglue.cdiunit.CdiRunner.methodBlock(CdiRunner.java:122)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/enterprise/inject/UnsatisfiedResolutionException
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:637)
at java.lang.ClassLoader.defineClass(ClassLoader.java:621)
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 org.jglue.cdiunit.CdiRunner.createTest(CdiRunner.java:69)
... 18 more


My dependencies are:

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <scope>test</scope>
        </dependency>
        <dependency>
<groupId>org.jglue.cdi-unit</groupId>
<artifactId>cdi-unit</artifactId>
<version>3.0.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.weld.se</groupId>
<artifactId>weld-se</artifactId>
<version>2.1.0.Final</version>
<scope>test</scope>
</dependency>

and my test class is:

import org.jglue.cdiunit.CdiRunner;
import org.junit.Test;
import org.junit.runner.RunWith;
 
@RunWith(CdiRunner.class)
public class CDIInterceptorTest {
@Test
public void testWithSingleParam() {
}
}
 

I am running this on Java 6,  is it supported?

TIA
-Alex

Bryn Cooke

unread,
Jun 17, 2014, 4:24:00 AM6/17/14
to cdi-...@googlegroups.com
Hi,
I tried your project with OpenJDK6 and it worked fine for me from the command line and eclipse.
The error message is saying that the CDI-Api jar is somehow on the classpath. API jars like CDI or Servlet typically have missing method implementations as they are not intended to be on the classpath except at compile time.

Check that your classpath is clean and that you haven't got any manual entries there.

Also you don't need to specify the Weld dependency unless you want to run a specific version of Weld. In that case you should exclude the dependency from the CDI-Unit entry.

Bryn

fcm...@scale.com.br

unread,
Sep 24, 2014, 7:45:46 PM9/24/14
to cdi-...@googlegroups.com
Hello,

The error happened for me too. I moved the maven CDI-Unit entry to the top of the dependencies. 

Then it changed to: 

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

tks

Flavio

Bryn Cooke

unread,
Sep 25, 2014, 3:34:54 AM9/25/14
to cdi-...@googlegroups.com
I just can't reproduce this. Can you paste your dependencies here?

Bryn

Bryn Cooke

unread,
Sep 25, 2014, 4:19:30 AM9/25/14
to cdi-...@googlegroups.com
I've pushed a change in to HEAD to give better error messages for API only classes on the classpath. It'll now tell you the class and the offending classpath entry.

If this works for you (feedback to https://github.com/BrynCooke/cdi-unit/issues/62) then I will do a new release.

I have deployed a snapshot to Sonatype if it makes it easier for you to test.

Bryn
Reply all
Reply to author
Forward
0 new messages