users@jaxb.java.net

NumberFormatException while unmarshalling an attribute of incorrect type (despite being detected as invalid by schema validator)

From: stefcl <stefatwork_at_gmail.com>
Date: Mon, 8 Mar 2010 02:55:00 -0800 (PST)

Hello,
I recently came across an error when trying to unmarshall an xml document
having attribute values of incorrect type, my validation event handler just
logs the error which results in the following :

2 cvc-datatype-valid.1.2.1: '30.11.2005 18:13:50' is not a valid value for
'integer'.
2 cvc-attribute.3: The value '30.11.2005 18:13:50' of attribute 'timestamp'
on element 'item' is not valid with respect to its type, 'long'.

Before returning true, so that parsing is not aborted. I would expect jaxb
to just ignore the faulty value and safely continue, but surprisingly I get
this exception right after :

Exception in thread "main" java.lang.NumberFormatException: For input
string: "30.11.2005 18:13:50"
        at
java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
        at java.lang.Long.parseLong(Long.java:412)
        at java.lang.Long.valueOf(Long.java:518)
        at
com.sun.xml.bind.DatatypeConverterImpl._parseLong(DatatypeConverterImpl.java:143)
        at
com.sun.xml.bind.v2.model.impl.RuntimeBuiltinLeafInfoImpl$19.parse(RuntimeBuiltinLeafInfoImpl.java:712)
        at
com.sun.xml.bind.v2.model.impl.RuntimeBuiltinLeafInfoImpl$19.parse(RuntimeBuiltinLeafInfoImpl.java:715)
        at
com.sun.xml.bind.v2.runtime.reflect.TransducedAccessor$CompositeTransducedAccessorImpl.parse(TransducedAccessor.java:241)
        at
com.sun.xml.bind.v2.runtime.unmarshaller.StructureLoader.startElement(StructureLoader.java:201)
        at
com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext._startElement(UnmarshallingContext.java:481)
        at
com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.startElement(UnmarshallingContext.java:459)
        at
com.sun.xml.bind.v2.runtime.unmarshaller.ValidatingUnmarshaller.startElement(ValidatingUnmarshaller.java:97)
        at
com.sun.xml.bind.v2.runtime.unmarshaller.SAXConnector.startElement(SAXConnector.java:148)
        at
org.xml.sax.helpers.XMLFilterImpl.startElement(XMLFilterImpl.java:527)
        at
com.prediggo.xml.parsing.internal.FakeNamespaceSaxFilter.startElement(FakeNamespaceSaxFilter.java:57)
        at
com.ctc.wstx.sr.BasicStreamReader.fireSaxStartElement(BasicStreamReader.java:1676)
        at
com.ctc.wstx.sax.WstxSAXParser.fireStartTag(WstxSAXParser.java:635)
        at com.ctc.wstx.sax.WstxSAXParser.fireEvents(WstxSAXParser.java:526)
        at com.ctc.wstx.sax.WstxSAXParser.parse(WstxSAXParser.java:452)
        at org.xml.sax.helpers.XMLFilterImpl.parse(XMLFilterImpl.java:333)
        at
com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:211)
        at
com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:184)
        at
javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:120)
        at
javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:103)
        at
com.prediggo.xml.parsing.XmlParsingService.marshallXml(XmlParsingService.java:331)
        at
com.prediggo.xml.parsing.XmlParsingService.openAndParseFile(XmlParsingService.java:265)
        at
com.prediggo.xml.parsing.XmlParsingService.parseFile(XmlParsingService.java:228)
        at
com.prediggo.xml.parsing.XmlParsingService.parseItemsFile(XmlParsingService.java:191)
        at largexmlparsingtests.Main.main(Main.java:42)
Java Result: 1

Schema validation errors are common as we are working with third-party
generated files. Under normal circumstances, JaxB just reports the error and
successfully resume the parsing operation. I don't know why but it seems
that in this case, it's still trying to parse the value, ignoring that it
was reported as invalid, causing a NumberFormatException to occur.

It seems that it only happens when the incorrect value is an attribute. The
same scenario in an element node type seems to work properly.

Could it be a bug? I use jaxb-ri-20091104
Thanks in advance.
-- 
View this message in context: http://old.nabble.com/NumberFormatException-while-unmarshalling-an-attribute-of-incorrect-type-%28despite-being-detected-as-invalid-by-schema-validator%29-tp27819644p27819644.html
Sent from the java.net - jaxb users mailing list archive at Nabble.com.