"duplicate class definition error" using jaxb in jboss

I use jaxb inside the jboss 5.0.1GA container and see a strange exception on startup. He appears only once.

From stacktrace, you can see that this is during the initialization of the class class FrameworkUtil class.

The FrameworkUtil 119 line looks like this:

JAXBContext j = JAXBContext.newInstance(Validate.class, Response.class ....<more classes>); 

Validate.java has this in it:

 @XmlRootElement(name="validate") public class Validate { List<String> userGroups; @XmlElementWrapper(name="userGroups") @XmlElement(name="item") public String[] getUserGroups() { if (userGroups != null) { return userGroups.toArray(new String[userGroups.size()]); } else return null; } public void setUserGroups(String[] userGrps) { userGroups = new ArrayList<String>(); if (userGrps != null) { for (String userGrp : userGrps) { userGroups.add(new String(userGrp)); } } } } 

There is a link to Validate in the stack trace. But sometimes stacktrace is different, and instead refers to the same field ( userGroups ) in Response.class .

Here's the stack trace:

 Mar 19, 2015 11:20:50 AM com.sun.xml.bind.v2.runtime.reflect.opt.Injector inject WARNING: duplicate class definition bug occured? Please report this : com/mycompany/ecommerce/message/beans/Validate$JaxbAccessorM_getUserGroups_setUserGroups_[Ljava_lang_String; java.lang.ClassFormatError: Illegal class name "com/mycompany/ecommerce/message/beans/Validate$JaxbAccessorM_getUserGroups_setUserGroups_[Ljava_lang_String;" in class file com/mycompany/ecommerce/messa ge/beans/Validate$JaxbAccessorM_getUserGroups_setUserGroups_[Ljava_lang_String; at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:800) at java.lang.ClassLoader.defineClass(ClassLoader.java:643) at sun.reflect.GeneratedMethodAccessor209.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at com.sun.xml.bind.v2.runtime.reflect.opt.Injector.inject(Injector.java:205) at com.sun.xml.bind.v2.runtime.reflect.opt.Injector.inject(Injector.java:85) at com.sun.xml.bind.v2.runtime.reflect.opt.AccessorInjector.prepare(AccessorInjector.java:89) at com.sun.xml.bind.v2.runtime.reflect.opt.OptimizedAccessorFactory.get(OptimizedAccessorFactory.java:114) at com.sun.xml.bind.v2.runtime.reflect.Accessor$GetterSetterReflection.optimize(Accessor.java:369) at com.sun.xml.bind.v2.runtime.property.ArrayProperty.<init>(ArrayProperty.java:65) at com.sun.xml.bind.v2.runtime.property.ArrayERProperty.<init>(ArrayERProperty.java:84) at com.sun.xml.bind.v2.runtime.property.ArrayElementProperty.<init>(ArrayElementProperty.java:96) at com.sun.xml.bind.v2.runtime.property.ArrayElementLeafProperty.<init>(ArrayElementLeafProperty.java:66) at sun.reflect.GeneratedConstructorAccessor172.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:526) at com.sun.xml.bind.v2.runtime.property.PropertyFactory.create(PropertyFactory.java:124) at com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.<init>(ClassBeanInfoImpl.java:179) at com.sun.xml.bind.v2.runtime.JAXBContextImpl.getOrCreate(JAXBContextImpl.java:515) at com.sun.xml.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:330) at com.sun.xml.bind.v2.runtime.JAXBContextImpl$JAXBContextBuilder.build(JAXBContextImpl.java:1140) at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:154) at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:121) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:248) at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:235) at javax.xml.bind.ContextFinder.find(ContextFinder.java:432) at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:637) at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:584) at com.mycompany.global.er.util.FrameworkUtil.<clinit>(FrameworkUtil.java:119) 
+7
java xml jboss jaxb
source share
1 answer

Have you checked this error ? It seems to be fixed in version 2.2.11 of the jaxb implementation.

Perhaps you could try replacing jaxb JAR files, they are probably located in your lib server if your webapp does not overwrite them in its own lib folder.

 <dependency> <groupId>com.sun.xml.bind</groupId> <artifactId>jaxb-impl</artifactId> <version>2.2.11</version> </dependency> 
+1
source share

All Articles