[ 
https://issues.apache.org/jira/browse/XERCESJ-1272?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Michael Glavassevich resolved XERCESJ-1272.
-------------------------------------------

    Resolution: Invalid

URLConnection.getInputStream() [1] returns an InputStream or throws an 
exception. The Java spec doesn't allow for it to return null. If it's doing 
that it's a bug in the I/O library not Xerces.  I see no value in Xerces 
checking for null here. It can do nothing to recover since it has no input to 
parse. You're going to get an exception either way.

Further I don't believe that's what's even happening here. If you look at the 
top of the stack trace you'll see that the NPE is being emitted from 
java.io.FilterInputStream. It's most likely that the invoker of the parser 
passed it a java.io.FilterInputStream (which was passed null to its constructor 
[2] instead of an InputStream instance); the NPE arising from calling any of 
its methods.

Caused by: java.lang.NullPointerException
    at java.io.FilterInputStream.read(FilterInputStream.java:66)
    at 
org.apache.xerces.impl.XMLEntityManager$RewindableInputStream.read(Unknown 
Source)
    at org.apache.xerces.impl.XMLEntityManager.setupCurrentEntity(Unknown 
Source)
    at org.apache.xerces.impl.XMLVersionDetector.determineDocVersion(Unknown 
Source)
    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)

[1] 
http://java.sun.com/j2se/1.5.0/docs/api/java/net/URLConnection.html#getInputStream()
[2] 
http://java.sun.com/j2se/1.5.0/docs/api/java/io/FilterInputStream.html#FilterInputStream(java.io.InputStream)

> NPE in XMLEntityManager
> -----------------------
>
>                 Key: XERCESJ-1272
>                 URL: https://issues.apache.org/jira/browse/XERCESJ-1272
>             Project: Xerces2-J
>          Issue Type: Bug
>    Affects Versions: 2.6.2, 2.9.1
>         Environment: Weblogic 8.1 SP 5 running on Solaris 2.10, Axis 1.4
>            Reporter: Shinta
>
> Our application runs on Weblogic 8.1 SP 5. It makes a webservice call to an 
> Axis webservice. When we ran our load tests, we would occasionally get the 
> following exception:
> my.exceptions.ProviderException: java.lang.NullPointerException
>     at my.ReferenceWebservicesPlugin.sendOutBoundResult(Unknown Source)
>     at 
> my.ejb.NBINotificationServiceMDB.onMessage(NBINotificationServiceMDB.java:60)
>     at weblogic.ejb20.internal.MDListener.execute(MDListener.java:400)
>     at 
> weblogic.ejb20.internal.MDListener.transactionalOnMessage(MDListener.java:333)
>     at weblogic.ejb20.internal.MDListener.onMessage(MDListener.java:298)
>     at weblogic.jms.client.JMSSession.onMessage(JMSSession.java:2686)
>     at weblogic.jms.client.JMSSession.execute(JMSSession.java:2598)
>     at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:224)
>     at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:183)
> Caused by: java.lang.NullPointerException
>     at org.apache.axis.AxisFault.makeFault(AxisFault.java:101)
>     at org.apache.axis.client.Call.invoke(Call.java:2446)
>     at org.apache.axis.client.Call.invoke(Call.java:2366)
>     at org.apache.axis.client.Call.invoke(Call.java:1812)
>     at 
> my.service.NotificationEventServiceSoapBindingStub.processDeviceActivationResult(Unknown
>  Source)  
>     ... 9 more
> Caused by: java.lang.NullPointerException                                     
>                                                           at 
> java.io.FilterInputStream.read(FilterInputStream.java:66)
>     at 
> org.apache.xerces.impl.XMLEntityManager$RewindableInputStream.read(Unknown 
> Source)
>     at org.apache.xerces.impl.XMLEntityManager.setupCurrentEntity(Unknown 
> Source)
>     at org.apache.xerces.impl.XMLVersionDetector.determineDocVersion(Unknown 
> Source)
>     at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
>     at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
>     at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
>     at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
>     at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown 
> Source)
>     at org.apache.xerces.jaxp.SAXParserImpl.parse(Unknown Source)
>     at 
> org.apache.axis.encoding.DeserializationContext.parse(DeserializationContext.java:227)
>     at org.apache.axis.SOAPPart.getAsSOAPEnvelope(SOAPPart.java:696)
>     at org.apache.axis.Message.getSOAPEnvelope(Message.java:435)
>     at org.apache.axis.client.Call.invokeEngine(Call.java:2804)
>     at org.apache.axis.client.Call.invoke(Call.java:2767)
>     at org.apache.axis.client.Call.invoke(Call.java:2443)
>     ... 12 more
> We originally ran the application with Xerces 2.6.2 and have tried 2.9.1. 
> Same issue happened on 2.9.1 as well.
> While looking at the source code for Xerces 2.9.1, I noticed this:
>        // create reader
>         InputStream stream = null;
>         Reader reader = xmlInputSource.getCharacterStream();
>         // First chance checking strict URI
>         String expandedSystemId = expandSystemId(literalSystemId, 
> baseSystemId, fStrictURI);
>         if (baseSystemId == null) {
>             baseSystemId = expandedSystemId;
>         }
>         if (reader == null) {
>             stream = xmlInputSource.getByteStream();
>             if (stream == null) {
>                 URL location = new URL(expandedSystemId);
>                 URLConnection connect = location.openConnection();
>                 if (!(connect instanceof HttpURLConnection)) {
>                     stream = connect.getInputStream();
>                 }
>                 else {
>                     boolean followRedirects = true;
>                     
>                     // setup URLConnection if we have an HTTPInputSource
>                     if (xmlInputSource instanceof HTTPInputSource) {
>                         final HttpURLConnection urlConnection = 
> (HttpURLConnection) connect;
>                         final HTTPInputSource httpInputSource = 
> (HTTPInputSource) xmlInputSource;
>                         
>                         // set request properties
>                         Iterator propIter = 
> httpInputSource.getHTTPRequestProperties();
>                         while (propIter.hasNext()) {
>                             Map.Entry entry = (Map.Entry) propIter.next();
>                             urlConnection.setRequestProperty((String) 
> entry.getKey(), (String) entry.getValue());
>                         }
>                         
>                         // set preference for redirection
>                         followRedirects = 
> httpInputSource.getFollowHTTPRedirects();
>                         if (!followRedirects) {
>                             setInstanceFollowRedirects(urlConnection, 
> followRedirects);
>                         }
>                     }
>                     
>                     stream = connect.getInputStream();
>                     
>                     // REVISIT: If the URLConnection has external encoding
>                     // information, we should be reading it here. It's located
>                     // in the charset parameter of Content-Type. -- mrglavas
>                     
>                     if (followRedirects) {
>                         String redirect = connect.getURL().toString();
>                         // E43: Check if the URL was redirected, and then
>                         // update literal and expanded system IDs if needed.
>                         if (!redirect.equals(expandedSystemId)) {
>                             literalSystemId = redirect;
>                             expandedSystemId = redirect;
>                         }
>                     }
>                 }
>             }
>             // wrap this stream in RewindableInputStream
>             stream = new RewindableInputStream(stream);
> Could it be that the call to "stream = connect.getInputStream()" returns 
> null? In this case the RewindableInputStream() will contain a null stream and 
> when we try to read it, we will get NPE?
> This code probably could be made more robust by checking for the null 
> stream....

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to