java.lang.NullPointerException

Spring JIRA | William Gorder | 4 years ago
tip
Your exception is missing from the Samebug knowledge base.
Here are the best solutions we found on the Internet.
Click on the to mark the helpful solution and get rewards for you help.
  1. 0

    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

    Spring JIRA | 4 years ago | William Gorder
    java.lang.NullPointerException
  2. 0

    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

    Spring JIRA | 4 years ago | William Gorder
    java.lang.NullPointerException
  3. Speed up your debug routine!

    Automated exception search integrated into your IDE

  4. 0

    NullPointerException during XML Unmarshalling

    Stack Overflow | 4 years ago | dareurdream
    java.lang.NullPointerException
  5. 0

    Null Pointer Exception in JAXB RI ClassFactory

    Stack Overflow | 2 years ago
    java.lang.NullPointerException

    1 unregistered visitors
    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. java.lang.NullPointerException

      No message provided

      at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse()
    2. Java RT
      AbstractUnmarshallerImpl.unmarshal
      1. com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1203)
      2. com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:203)
      3. com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:175)
      4. javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:140)
      5. javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:123)
      5 frames
    3. Spring Object/XML Marshalling
      Jaxb2Marshaller.unmarshal
      1. org.springframework.oxm.jaxb.Jaxb2Marshaller.unmarshal(Jaxb2Marshaller.java:738)
      2. org.springframework.oxm.jaxb.Jaxb2Marshaller.unmarshal(Jaxb2Marshaller.java:720)
      2 frames