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

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

Comments

@spring-issuemaster
Copy link
Collaborator

@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.

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

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

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


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
Projects
None yet
2 participants
You can’t perform that action at this time.