#158 Dozer should load classes using ContextClassLoader

Dozer v4.4.1
closed-fixed
nobody
None
5
2009-01-10
2009-01-05
Roman Stumm
No

Since Dozer4.3 dozer does not find classes in the context classloader, so that we get net.sf.dozer.util.mapping.MappingException: java.lang.ClassNotFoundException
when mapping classes located in the .war archive (dozer.jar is located in the parent classloader, e.g. in the lib directory of the appserver).

This worked correctly in previous versions of dozer, because it used the ContextClassLoader.

Class MappingUtils has been changed in Dozer4.3 (ff.) so that dozer only finds classes that are in the same classload as dozer itself:

New Code (since 4.3)
public static Class loadClass(String name) {
Class result = null;
try {
result = Class.forName(name);
} catch (ClassNotFoundException e) {
MappingUtils.throwMappingException(e);
}
return result;
}

I suggest, that you revert the change and use the former code again, that fixes the bug:

Code in Dozer4.2 and before:

public static Class loadClass(String name) {
Class result = null;
try {
result = Thread.currentThread().getContextClassLoader().loadClass(name);
} catch (ClassNotFoundException e) {
MappingUtils.throwMappingException(e);
}
return result;
}

Best regards,
Roman Stumm

Discussion

  • Roman Stumm

    Roman Stumm - 2009-01-05

    Another suggestion: Dozer is already using commons-lang

    So the simplest way to load a class would be: org.apache.commons.lang.ClassUtils.getClass(String name).

    (org.apache.commons.lang.ClassUtils is also using the ContextClassLoader)

     
  • dmitry (lv)

    dmitry (lv) - 2009-01-05

    Thank you for reporting this issue.
    We will be preparing 4.4.1 release with this fix in the closest time.

     
  • dmitry (lv)

    dmitry (lv) - 2009-01-10

    Fixed, included in 4.4.1 release

     
  • dmitry (lv)

    dmitry (lv) - 2009-01-10
    • milestone: --> Dozer v4.4.1
    • 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