java.lang.NullPointerException

There are no available Samebug tips for this exception. Do you have an idea how to solve this issue? A short tip would help users who saw this issue last week.

  • This appears to be a regression, since the error did not occur in 3.2.0.RELEASE. A work around is to create the StreamSource using an InputStream rather than a File. What happens is this: When creating a StreamSource with a file input i.e. {code} jaxb2Marshaller .unmarshal(new StreamSource(new ClassPathResource("my-resource-descriptor.xml") .getFile())); {code} in the processSource(...) method the first if/else block is skipped (since its a file and the new SaxSource is created with a null inputSource. This results in a null pointer exception down stream. {code} private Source processSource(Source source) { if (StaxUtils.isStaxSource(source) || source instanceof DOMSource) { return source; } XMLReader xmlReader = null; InputSource inputSource = null; if (source instanceof SAXSource) { SAXSource saxSource = (SAXSource) source; xmlReader = saxSource.getXMLReader(); inputSource = saxSource.getInputSource(); } else if (source instanceof StreamSource) { StreamSource streamSource = (StreamSource) source; if (streamSource.getInputStream() != null) { inputSource = new InputSource(streamSource.getInputStream()); } else if (streamSource.getReader() != null) { inputSource = new InputSource(streamSource.getReader()); } } try { if (xmlReader == null) { xmlReader = XMLReaderFactory.createXMLReader(); } xmlReader.setFeature("http://xml.org/sax/features/external-general-entities", this.processExternalEntities); return new SAXSource(xmlReader, inputSource); //input source is null here, if using File } catch (SAXException ex) { logger.warn("Processing of external entities could not be disabled", ex); return source; } } {code} Here is an excerpt from the null pointer java.lang.NullPointerException at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1203) at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:203) at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:175) at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:140) at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:123) at org.springframework.oxm.jaxb.Jaxb2Marshaller.unmarshal(Jaxb2Marshaller.java:738) at org.springframework.oxm.jaxb.Jaxb2Marshaller.unmarshal(Jaxb2Marshaller.java:720) at
    via by William Gorder,
  • This appears to be a regression, since the error did not occur in 3.2.0.RELEASE. A work around is to create the StreamSource using an InputStream rather than a File. What happens is this: When creating a StreamSource with a file input i.e. {code} jaxb2Marshaller .unmarshal(new StreamSource(new ClassPathResource("my-resource-descriptor.xml") .getFile())); {code} in the processSource(...) method the first if/else block is skipped (since its a file and the new SaxSource is created with a null inputSource. This results in a null pointer exception down stream. {code} private Source processSource(Source source) { if (StaxUtils.isStaxSource(source) || source instanceof DOMSource) { return source; } XMLReader xmlReader = null; InputSource inputSource = null; if (source instanceof SAXSource) { SAXSource saxSource = (SAXSource) source; xmlReader = saxSource.getXMLReader(); inputSource = saxSource.getInputSource(); } else if (source instanceof StreamSource) { StreamSource streamSource = (StreamSource) source; if (streamSource.getInputStream() != null) { inputSource = new InputSource(streamSource.getInputStream()); } else if (streamSource.getReader() != null) { inputSource = new InputSource(streamSource.getReader()); } } try { if (xmlReader == null) { xmlReader = XMLReaderFactory.createXMLReader(); } xmlReader.setFeature("http://xml.org/sax/features/external-general-entities", this.processExternalEntities); return new SAXSource(xmlReader, inputSource); //input source is null here, if using File } catch (SAXException ex) { logger.warn("Processing of external entities could not be disabled", ex); return source; } } {code} Here is an excerpt from the null pointer java.lang.NullPointerException at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1203) at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:203) at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:175) at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:140) at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:123) at org.springframework.oxm.jaxb.Jaxb2Marshaller.unmarshal(Jaxb2Marshaller.java:738) at org.springframework.oxm.jaxb.Jaxb2Marshaller.unmarshal(Jaxb2Marshaller.java:720) at
    via by William Gorder,
  • Null Pointer Exception in JAXB RI ClassFactory
    via by Unknown author,
  • JAXB Unmarshalling from .xml file to jlist
    via by Unknown author,
  • Xml to java object usig jaxb
    via Stack Overflow by Jhelum Dasgupta
    ,
    • java.lang.NullPointerException at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1203) at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:203) at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:175) at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:140) at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:123) at org.springframework.oxm.jaxb.Jaxb2Marshaller.unmarshal(Jaxb2Marshaller.java:738) at org.springframework.oxm.jaxb.Jaxb2Marshaller.unmarshal(Jaxb2Marshaller.java:720)

    Users with the same issue

    Unknown visitor2 times, last one,