#267 Dozer has semi-undocumented dependency on XMLBeans

Dozer v5.3.0
Matt Brown

In Dozer's POM, org.apache.xmlbeans:xmlbeans is listed as an optional dependency.

However, attempting to use Dozer to handle a simple mapping in which Dozer needs to build the dest bean itself in a project that does not have xmlbeans as a dependency itself results in a NoClassDefFoundError.

Caused by: java.lang.NoClassDefFoundError: org/apache/xmlbeans/XmlObject
at org.dozer.factory.ConstructionStrategies$XMLBeansBased.isApplicable(ConstructionStrategies.java:191)
at org.dozer.factory.DestBeanCreator.create(DestBeanCreator.java:65)
at org.dozer.MappingProcessor.map(MappingProcessor.java:176)

The code that triggered this exception on my end looks something like:

final T obj = dao.get(id);
T copy = mapper.map(obj, clazz);

T is a type parameter for this method, clazz is defined as Class<T>

In effect this code simply retrieves an object instance from one of my DAOs and then passes it to Dozer to create a copy of itself (the reason for doing this is unrelated, but I am attempting to map the bean to a new instance to remove Hibernate proxies from the POJO instance).

From looking at the source code in Dozer 5.2.2 this error appears to occur because DestBeanMapper.create(BeanCreationDirective) polls each BeanCreationStrategy until it finds one that is applicable for the directive. The fourth entry in the availableStrategies array is ConstructionStrategies.XMLBeansBased, which attempts to use XmlBeans classes without checking to see if they are available. The BeanCreationStrategy which is ultimately used for my type, byConstructor, is last in the list.

Thus if DestBeanCreator needs to create the destBean with it's constructor, it will always first check if XmlBeans strategy is applicable - even if XmlBeans is not on the classpath.

I'd suggest either one of two changes: 1) remove optional=true for the xmlbeans dependency in the POM, or 2) add logic to ConstructionStrategies.XMLBeansBased to handle situations where the XmlObject class cannot be found (and return false instead of propogating any ClassDefNotFoundExceptions or NoClassDefFoundErrors).


  • Matt Brown

    Matt Brown - 2010-07-01
    • milestone: --> 1129554
  • dmitry (lv)

    dmitry (lv) - 2010-07-07
    • milestone: 1129554 --> Dozer v5.3.0
    • assigned_to: nobody --> buzdin
  • dmitry (lv)

    dmitry (lv) - 2010-07-07

    thanks for the bug report. I have not realized that we are introducing this dependency. We will go with option 2 most probably as XmlBeans are absolutly not required to be packaged with Dozer.

  • dmitry (lv)

    dmitry (lv) - 2010-07-09

    direct reference replaced with reflective one. Dozer was checked to be working well without XmlBeans.

  • dmitry (lv)

    dmitry (lv) - 2010-07-09
    • status: open --> closed-fixed

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks