Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"duplicate class definition bug occured" using jaxb in jboss

I'm using jaxb inside a jboss 5.0.1GA container, and seeing a strange exception at startup. It appears once only.

From the stacktrace you can see that it is during the class initialisation of FrameworkUtil class.

FrameworkUtil line 119 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));
            }
        }
    }
}

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

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)
like image 806
mdarwin Avatar asked Mar 19 '15 15:03

mdarwin


1 Answers

Did you check this bug out ? Seems to be fixed in version 2.2.11 of jaxb implementation.

Maybe you could try and replace jaxb JAR files, they're probably in you server's lib, unless your webapp overwrites them in it's own lib folder.

<dependency>
    <groupId>com.sun.xml.bind</groupId>
    <artifactId>jaxb-impl</artifactId>
    <version>2.2.11</version>
</dependency>
like image 184
Iulian Plesoianu Avatar answered Oct 13 '22 23:10

Iulian Plesoianu