I am experiencing a NullPointerException during on-demand validation.
I create an instance of my Settings class using the generated
ObjectFactory.createSettings() method.
I immediately attempt to validate it (validateRoot) and I get the
NullPointerException depicted below rather than the ValidationException
I was expecting.
Stack-trace and full schema below.
Thanks
Marcus
=== stacktrace ===
java.lang.NullPointerException
at com.sun.xml.bind.validator.MSVValidator.childAsElements(MSVValidator.java:249)
at com.aspective.customer.config.xml.impl.SettingsTypeImpl.serializeElements(SettingsTypeImpl.java:40)
at com.aspective.customer.config.xml.impl.SettingsImpl.serializeElements(SettingsImpl.java:41)
at com.sun.xml.bind.validator.MSVValidator._validate(MSVValidator.java:88)
at com.sun.xml.bind.validator.MSVValidator.validate(MSVValidator.java:69)
at com.sun.xml.bind.validator.ValidationContext.validate(ValidationContext.java:78)
at com.sun.xml.bind.validator.ValidatorImpl.validate(ValidatorImpl.java:99)
at com.sun.xml.bind.validator.ValidatorImpl.validateRoot(ValidatorImpl.java:80)
=== settings.xsd ===
<xsd:schema xmlns:xsd="
http://www.w3.org/2001/XMLSchema"
xmlns:jxb="
http://java.sun.com/xml/ns/jaxb"
jxb:version="1.0">
<!-- the root element for the settings XML file -->
<xsd:element name="settings" type="SettingsType"/>
<xsd:simpleType name="trimmedString">
<xsd:restriction base="xsd:string">
<xsd:annotation>
<xsd:appinfo>
<jxb:javaType name="java.lang.String"
parse="com.aspective.common.jaxb.TrimmedString.trim"
print="com.aspective.common.jaxb.TrimmedString.trim">
</jxb:javaType>
</xsd:appinfo>
</xsd:annotation>
</xsd:restriction>
</xsd:simpleType>
<!-- this is the top-level container for settings -->
<xsd:complexType name="SettingsType">
<xsd:sequence>
<xsd:element name="database" type="DatabaseSettings"/>
</xsd:sequence>
</xsd:complexType>
<!-- database settings -->
<xsd:complexType name="DatabaseSettings">
<xsd:sequence>
<xsd:element name="username">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:maxLength value="16"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
<xsd:element name="password">
<xsd:simpleType>
<xsd:restriction base="trimmedString">
<xsd:maxLength value="16"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>