users@jaxb.java.net

[JAXB-1.x] NPE while unmarshalling empty long element

From: Kostis Anagnostopoulos <ankostis_at_gmail.com>
Date: Thu, 20 Jul 2006 20:58:21 +0300

Hi,

i think there is a problem when unmarshalling empty xml elements typed
long (i'm suspecting other numeric types might also have the same
problem).

The element involved has the following schema definition:
      <xsd:element name="someId" type="xsd:long" />

The xml to be unmarshalled is like that:
    <someId/>

I have tried adding nillable="true" attribute to element definition,
and jaxb-customizing target-type to java.lang.Long, with no results.

Is this a BUG ?

By looking at the code, i believe it is easy to be fixed.


Here is the stacktrace during unmarshalling:

java.lang.NullPointerException
        at com.sun.xml.bind.DatatypeConverterImpl.parseLong(DatatypeConverterImpl.java:98)
        at javax.xml.bind.DatatypeConverter.parseLong(DatatypeConverter.java:157)
        at gr.forthnet.frepor.xmltypes.impl.FreePortTypeImpl$Unmarshaller.eatText3(FreePortTypeImpl.java:914)
        at gr.forthnet.frepor.xmltypes.impl.FreePortTypeImpl$Unmarshaller.handleText(FreePortTypeImpl.java:852)
        at gr.forthnet.frepor.xmltypes.impl.runtime.AbstractUnmarshallingEventHandlerImpl.text(AbstractUnmarshallingEentHandlerImpl.java:82)
        at gr.forthnet.frepor.xmltypes.impl.runtime.SAXUnmarshallerHandlerImpl.consumeText(SAXUnmarshallerHandlerImpljava:211)
        at gr.forthnet.frepor.xmltypes.impl.runtime.SAXUnmarshallerHandlerImpl.processText(SAXUnmarshallerHandlerImpljava:215)
        at gr.forthnet.frepor.xmltypes.impl.runtime.SAXUnmarshallerHandlerImpl.endElement(SAXUnmarshallerHandlerImpl.ava:140)
        at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.endElement(AbstractSAXParser.java:633)
        at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanEndElement(XMLNSDocumentScannerImpl.jva:719)
        at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(MLDocumentFragmentScannerImpl.java:1685)
        at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScanerImpl.java:368)
        at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:834)
        at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:764)
        at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:148)
        at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1242)
        at gr.forthnet.frepor.xmltypes.impl.runtime.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:140)
        at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:131)
        at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:178)