users@jaxb.java.net

different behaviors of default val attrs depending on underlying type?

From: jonathan gold <dev_at_samizdatdigital.org>
Date: Thu, 20 Oct 2005 09:30:23 -0700

if i have an attribute whose type is an Enum with a default value
specified, the generated code ends up returning null, not the default
enum value, which leads to downstream NullPointerExceptions.

to repro, do something like this:

<simpleType name="FooType">
   <restriction base="string">
     <enumeration value="happy"/>
     <enumeration value="sad"/>
   </restriction>
</simpleType>

and something like this:

<complexType name="BadAttrExampleType">
   <attribute name="null-pointer-exception-attr"
              type="FooType"
              use="optional"
              default="sad"/>
</complexType>


generates straight getter code:

public FooType getNullPointerExceptionAttr() {
   return nullPointerExceptionAttr;
}

instead of the expected version with the if/else check which returns the
default. if i change the attribute type to something standard, like
xsd:string, then the code generated is correct.

is this expected?

jon