This kind of seems like a bug in JAXB (although I can't claim that I thoroughly understand the problem). Have you thought about email the JAXB users list about this and seeing if we can get a fix in for 2.0.3? Or is it not really a bug?

- Dan

Andrea Smyth wrote:

When you instantiate a class that is mapped from an element which has a base64Binary attribute with a default value, and subsequently call the getter for this attribute, the invocation will fail with a NPE unless somwhere in the code a DatatypeConverter was set via DatatypeConverter.setDatatypeConverter(javax.xml.bind.DatatypeConverterInterface converter):

e.g. generated code:

public class Foo {
...
public byte[] getBase64BinaryAttr() {
       if (base64BinaryAttr == null) {
           return DatatypeConverter.parseBase64Binary("wxyz");
       } else {
           return base64BinaryAttr;
       }
   }
}

application code:

Foo foo = new ObjectFactory().createFoo();
DatatypeConverter.setDatatypeConverter(new DatatypeConverterImpl());
byte[] value = foo.getBase64BinaryAttr()

Should we take care that somewhere in the runtime a DatatypeConverter is set, possibly through loading (but not necessarily registering) an extension in the rt-databinding-jaxb module? From the javadoc: " JAXB Providers are required to call this method at some point before allowing any of the JAXB client marshal or unmarshal operations to occur". We cannot take the DatatypeConverterImpl provided by sun (in the com.sun.xml.bind jaxb-impl.jar) as this has a protected constructor, but could use the one from jaxme project http://ws.apache.org/jaxme/

Thoughts?

Andrea.




--
Dan Diephouse
(616) 971-2053
Envoi Solutions LLC
http://netzooid.com

Reply via email to