Search code examples
javadeploymentwildflycdiweld

org.jboss.classfilewriter.DuplicateMemberException


While deploying my application on Wildfly I get the following error:

17:28:25,571 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-3) MSC000001: Failed to start service jboss.deployment.unit."Restaurant-1.1-SNAPSHOT.war".WeldStartService: org.jboss.msc.service.StartException in service jboss.deployment.unit."Restaurant-1.1-SNAPSHOT.war".WeldStartService: Failed to start service
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1904)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: org.jboss.weld.exceptions.WeldException: WELD-001524: Unable to load proxy class for bean Managed Bean [class com.naigoapps.restaurant.model.dao.RestaurantTableDao] with qualifiers [@Any @Default] with class class com.naigoapps.restaurant.model.dao.RestaurantTableDao using classloader ModuleClassLoader for Module "deployment.Restaurant-1.1-SNAPSHOT.war:main" from Service Module Loader
at org.jboss.weld.bean.proxy.ProxyFactory.getProxyClass(ProxyFactory.java:371)
at org.jboss.weld.injection.producer.SubclassedComponentInstantiator.createEnhancedSubclass(SubclassedComponentInstantiator.java:114)
at org.jboss.weld.injection.producer.SubclassedComponentInstantiator.initEnhancedSubclass(SubclassedComponentInstantiator.java:86)
at org.jboss.weld.injection.producer.SubclassedComponentInstantiator.<init>(SubclassedComponentInstantiator.java:79)
at org.jboss.weld.injection.producer.SubclassedComponentInstantiator.forInterceptedDecoratedBean(SubclassedComponentInstantiator.java:63)
at org.jboss.weld.injection.producer.BeanInjectionTarget.initializeAfterBeanDiscovery(BeanInjectionTarget.java:121)
at org.jboss.weld.injection.producer.InjectionTargetInitializationContext.initialize(InjectionTargetInitializationContext.java:42)
at org.jboss.weld.injection.producer.InjectionTargetService.initialize(InjectionTargetService.java:63)
at org.jboss.weld.bootstrap.WeldStartup.deployBeans(WeldStartup.java:433)
at org.jboss.weld.bootstrap.WeldBootstrap.deployBeans(WeldBootstrap.java:83)
at org.jboss.as.weld.WeldStartService.start(WeldStartService.java:95)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1948)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1881)
... 3 more
Caused by: org.jboss.weld.exceptions.WeldException: Method  already exists. Method: getTargetClass Parameters:[] Return Type: Ljava/lang/Class;
at org.jboss.weld.bean.proxy.InterceptedSubclassFactory.addSpecialMethods(InterceptedSubclassFactory.java:386)
at org.jboss.weld.bean.proxy.InterceptedSubclassFactory.addMethods(InterceptedSubclassFactory.java:116)
at org.jboss.weld.bean.proxy.ProxyFactory.createProxyClass(ProxyFactory.java:469)
at org.jboss.weld.bean.proxy.ProxyFactory.getProxyClass(ProxyFactory.java:364)
... 15 more
Caused by: org.jboss.classfilewriter.DuplicateMemberException: Method  already exists. Method: getTargetClass Parameters:[] Return Type: Ljava/lang/Class;
at org.jboss.classfilewriter.ClassFile.addMethod(ClassFile.java:133)
at org.jboss.classfilewriter.ClassFile.addMethod(ClassFile.java:148)
at org.jboss.weld.bean.proxy.InterceptedSubclassFactory.addSpecialMethods(InterceptedSubclassFactory.java:378)
... 18 more

These are my source files:

public interface Dao<E extends BaseEntity> {

    public Class<E> getTargetClass();
    public String getOrderByClause();

}


public abstract class AbstractDao<E extends BaseEntity> implements Dao<E>{

    [...]

    @Override
    public String getOrderByClause() {
        return null;
    }

}


public class RestaurantTableDao extends AbstractDao<RestaurantTable>{

    @Override
    public String getOrderByClause() {
        return "name";
    }

    @Override
    public Class<RestaurantTable> getTargetClass() {
        return RestaurantTable.class;
    }

}

It seems that methods defined in abstract class and interface have some problems. Before adding the 2 methods getOrderByClause and getTargetClass the problem didn't occur


Solution

  • It's a coincidence (or fate?), that Weld's proxy classes define getTargetClass() method as well with same signature, taking in account type erasure.

    Hence, as the exception says:

    org.jboss.weld.exceptions.WeldException: 
    Method  already exists.
    Method: getTargetClass Parameters:[] Return Type: Ljava/lang/Class;
    

    ... and because this is how Weld has to work and work, the safest, easiest & quickest way would be to just rename your method.

    Bonus: If you wonder what the hell proxies are, here is a brief article from Stuart Douglas about Weld, which is quite old, but still got the point.