I get a strange error when Im trying to unit test a Java class dealing with JSF components (javax.faces.model.SelectItem). The error I get is this:
java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/faces/model/SelectItem
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
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:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
...
It then reaches my code (in ItemOptionsHandler.java):
SelectItem[] items = new SelectItem[itemList.size()];
What's this error all about???
Thankful for help!
This is the class I want to test:
package foo.web.converters;
import java.io.Serializable;
import java.util.List;
import javax.ejb.EJB;
import javax.faces.model.SelectItem;
import foo.business.facade.ItemFacade;
import foo.model.MyType;
public class ItemOptionsHandler implements Serializable {
@EJB
private ItemFacade facade;
public void setFacade(ItemFacade facade) {
this.facade = facade;
}
public SelectItem[] getSupplierItems() {
List<MyType> itemList = facade.getSupplierItems();
SelectItem[] items = new SelectItem[itemList.size()];
int i = 0;
// more stuff
return items;
}
}
This is the test:
package foo.web.converters;
import java.util.ArrayList;
import java.util.List;
import javax.faces.model.SelectItem;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;
import foo.facade.ItemFacade;
import foo.model.MyModel;
public class ItemOptionsHandlerTest {
private ItemOptionsHandler instance = null;
public ItemOptionsHandlerTest() {
}
@BeforeClass
public static void setUpClass() throws Exception {
}
@AfterClass
public static void tearDownClass() throws Exception {
}
@Before
public void setUp() {
instance = new ItemOptionsHandler();
instance.setFacade(new BusinessFacadeTemp());
}
@After
public void tearDown() {
}
@Test
public void testGetSupplierItems() {
System.out.println("getSupplierGroups");
SelectItem[] expResult = null;
SelectItem[] result = instance.getSupplierItems();
assertEquals(expResult, result);
}
private class BusinessFacadeTemp implements ItemFacade {
@Override
public List<MyTest> getSupplierItems() {
return null;
}
}
}
Here are some of the dependencies:
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>6.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>jsr250-api</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>javax.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>javax.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>1.2-b19</version>
</dependency>
Are you using maven to resolve dependencies? If so, here seems to be an answer: http://weblogs.java.net/blog/ludo/archive/2007/01/java_ee_5_apis.html
You can download .jar and use it from your disk:
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>6.0</version>
<scope>provided</scope>
<systemPath>/path/to/your/jar</systemPath>
</dependency>