There are certain illegal values of an xs:boolean that return false when they should return null, namely values that start with t and f. In addition, if the string literals "t" and "f" are passed in, this will cause an unmarshalling error: Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: 1 at java.lang.AbstractStringBuilder.charAt(AbstractStringBuilder.java:203) [rt.jar:1.7.0_55] at java.lang.StringBuilder.charAt(StringBuilder.java:72) [rt.jar:1.7.0_55] at com.sun.xml.bind.DatatypeConverterImpl._parseBoolean(DatatypeConverterImpl.java:260)
Upstream Jira: https://java.net/jira/browse/JAXB-1019
Spec references: ------------------------------------------------------------------------ JAXB 2.2 spec, section B.3.8.1: Unparseable Data for Simple Types (p312) If simple type data cannot be parsed into a java datatype, then the value of the java datatype must not change the current set value. An access to the datatype must return the value as specified in Section B.3.8.2, “Missing element information item”. If the conversion of lexical representation into a value results in an exception, then the exception must be caught and a validation event reported. This is to ensure that such conversion errors do not terminate unmarshalling. B.3.8.2 Missing element information item Property or field access must return the value specified in Section B.3.8.4, “Value for missing elements/attributes” B.3.8.4 Value for missing elements/attributes If an attribute or an element is missing from an XML instance, then unmarshal will not change the current set value. An access to the property will return the set value or if unset, the uninitialized value. The uninitialized value of the property or field depends upon it's type. If the type is 1. int-valueis0 2. boolean - value is false 3. a reference (must be mapped to a simple type) - value is null. ... ------------------------------------------------------------------------ XML Schema, part 2, secion 3.2.2: Primitive Datatypes: boolean 3.2.2.1 Lexical representation An instance of a datatype that is defined as ·boolean· can have the following legal literals {true, false, 1, 0}. ------------------------------------------------------------------------ So I interpret the above specs like this: - The valid boolean values are {true, false, 1, 0}, excluding whitespace around the values - If it's not one of those values, then: - If the type is a primitive "boolean", the value is false (default) - If the type is "java.lang.Boolean" (i.e. an object reference), then the value is null (default) (Of course the invalid value should throw an exception if schema validation is enabled; we are only talking about the default unmarshalling value with schema validation disabled.)
Should be fixed by jaxb upgrade to 2.2.5-redhat-9: https://bugzilla.redhat.com/show_bug.cgi?id=1127326
Verified on 6.4.0.DR1