Hi there,

I'm trying to (junit) test some code via an ant task. In this unit test
a castor generated object is marshalled to xml.
This marshalling now fails because of a null pointer:
 [junit] Testcase: testUserType took 0,174 sec
 [junit]     Caused an ERROR
 [junit] null
 [junit] java.lang.NullPointerException
 [junit]     at
org.exolab.castor.xml.util.ClassDescriptorResolverImpl.loadPackageMappin
g(ClassDescriptorResolverImpl.java:802)
 [junit]     at
org.exolab.castor.xml.util.ClassDescriptorResolverImpl.resolve(ClassDesc
riptorResolverImpl.java:258)
 [junit]     at
org.exolab.castor.xml.Validator.validate(Validator.java:111)
 [junit]     at
org.exolab.castor.xml.Marshaller.validate(Marshaller.java:2482)
 [junit]     at
org.exolab.castor.xml.Marshaller.marshal(Marshaller.java:811)

The code in 0.9.7 did work, >0.9.9 did have this problem.

The code here assumes that a class loader exists for a given class
(which is ofcourse true, otherwise it couldn't be executed ;-). From the
java API doc, 'null' may be returned instead of the bootstrap class
loader, so the class loader may not always be represented by an actual
class.

The following code should remedy this, in
org.exolab.castor.xml.util.ClassDescriptorResolverImpl#loadPackageList,
lines 718 - 721:
        URL url = null; 
        if (loader == null) loader = _loader;
        if (loader == null) loader = getClass().getClassLoader();
        if (loader != null) url = loader.getResource(filename);

The same goes for the method
org.exolab.castor.xml.util.ClassDescriptorResolverImpl#loadPackageMappin
g, lines 801-804
       URL url = null;
        if (loader == null) loader = _loader;
        if (loader == null) loader = getClass().getClassLoader();
        if (loader != null) url = loader.getResource(filename);

Now I don't see the NPE anymore. :-)

Hope this helps,

Rutger Lubbers




-------------------------------------------------
If you wish to unsubscribe from this list, please
send an empty message to the following address:

[EMAIL PROTECTED]
-------------------------------------------------

Reply via email to