Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JaxB2Marshaller passes null InputSource to SaxSource constructor under certain condition [SPR-10828] #15454

spring-issuemaster opened this issue Aug 12, 2013 · 0 comments


Copy link

@spring-issuemaster spring-issuemaster commented Aug 12, 2013

William Gorder opened SPR-10828 and commented

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.

            .unmarshal(new StreamSource(new ClassPathResource("my-resource-descriptor.xml")

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.

       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();

                     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;

Here is an excerpt from the null pointer

at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(
at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(
at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(
at org.springframework.oxm.jaxb.Jaxb2Marshaller.unmarshal(
at org.springframework.oxm.jaxb.Jaxb2Marshaller.unmarshal(

Affects: 3.2.4

1 votes, 2 watchers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
2 participants
You can’t perform that action at this time.