You are viewing a plain text version of this content. The canonical link for it is here.
Posted to soap-dev@xml.apache.org by Ryo Neyama <ne...@trl.ibm.co.jp> on 2000/10/13 10:32:21 UTC

NullPointerException in unmarshalling

Hi,

A NullPointerException is thrown in unmarshalling an XML in which SOAP
Body element has "Id" attribute. I'm wondering setting an "Id"
attribute is allowed according to the schema of SOAP, because SOAP Body
element allows any attribute.

My environment is:
   Apache SOAP: The latest version in CVS
   Xerces 1.2.0

The reason seems to be that the namespace URI of "Id" attribute is null.
The exception was as follows:
--------- Begin exception
Exception in thread "main" java.lang.NullPointerException
	at org.apache.soap.util.xml.QName.setNamespaceURI(QName.java:108)
	at org.apache.soap.util.xml.QName.<init>(QName.java:102)
	at org.apache.soap.AttributeHandler.unmarshall(AttributeHandler.java:231)
	at org.apache.soap.Body.unmarshall(Body.java:183)
	at org.apache.soap.Envelope.unmarshall(Envelope.java:243)
	at test.main(test.java:11)
--------- End exception

The test program that causes the NullPointerException is as follows:
--------- Begin test program
import java.io.*;

import org.w3c.dom.Document ;
import org.apache.soap.Envelope ;
import org.apache.soap.util.xml.XercesParserLiaison ;

public class test {
    public static void main(String[] args) throws Exception {
        String xml ="<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\"><s:Body Id=\"body\"></s:Body></s:Envelope>";
        Document dom = new XercesParserLiaison().read("test", new StringReader(xml)) ;
        Envelope.unmarshall(dom.getDocumentElement()) ;
    }
}
--------- End test program

Could you fix the problem? Or, shall I send you a patch?
Thanks in advance.

Regards,
    Ryo Neyama @ IBM Research, Tokyo Research Laboratory
    Internet Technology
    neyama@trl.ibm.co.jp

Re: NullPointerException in unmarshalling

Posted by Ryo Neyama <ne...@trl.ibm.co.jp>.
Hello.

> > A NullPointerException is thrown in unmarshalling an XML in which SOAP
> > Body element has "Id" attribute. I'm wondering setting an "Id"
> > attribute is allowed according to the schema of SOAP, because SOAP Body
> > element allows any attribute.

> Anyway, the problem is produced by the following code.
> I'll try to fix the bug and post a patch.

Here is a quick hack for the problem.
Please commit the patch if it is reasonable for you.

****************** Begin patch
Index: src/org/apache/soap/AttributeHandler.java
===================================================================
RCS file: /home/cvspublic/xml-soap/java/src/org/apache/soap/AttributeHandler.java,v
retrieving revision 1.3
diff -r1.3 AttributeHandler.java
131a132
>     if ("" == namespaceURI) return null ;
157c158,159
<       nsStack.addNSDeclaration(namespacePrefix, namespaceURI);
---
>       if (namespacePrefix != null)
>         nsStack.addNSDeclaration(namespacePrefix, namespaceURI);
211,212c213,217
<       sink.write(' ' + getPrefixFromURI(attrQName.getNamespaceURI()) +
<                  ':' + attrQName.getLocalPart() + "=\"" +
---
>       sink.write(' ') ;
>       String nsPrefix ;
>       if ((nsPrefix = getPrefixFromURI(attrQName.getNamespaceURI())) != null)
>         sink.write(nsPrefix + ':') ;
>       sink.write(attrQName.getLocalPart() + "=\"" +
Index: src/org/apache/soap/util/xml/QName.java
===================================================================
RCS file: /home/cvspublic/xml-soap/java/src/org/apache/soap/util/xml/QName.java,v
retrieving revision 1.4
diff -r1.4 QName.java
108c108
<     this.namespaceURI = namespaceURI.intern();
---
>     this.namespaceURI = (namespaceURI == null ? "" : namespaceURI).intern();
****************** End patch

    Ryo Neyama @ IBM Research, Tokyo Research Laboratory
    Internet Technology
    neyama@trl.ibm.co.jp
    +81-46-215-4322 (Phone) / +81-46-273-7428 (FAX)

Re: NullPointerException in unmarshalling

Posted by Ryo Neyama <ne...@trl.ibm.co.jp>.
Hello.

> > A NullPointerException is thrown in unmarshalling an XML in which SOAP
> > Body element has "Id" attribute. I'm wondering setting an "Id"
> > attribute is allowed according to the schema of SOAP, because SOAP Body
> > element allows any attribute.

> Anyway, the problem is produced by the following code.
> I'll try to fix the bug and post a patch.

Here is a quick hack for the problem.
Please commit the patch if it is reasonable for you.

****************** Begin patch
Index: src/org/apache/soap/AttributeHandler.java
===================================================================
RCS file: /home/cvspublic/xml-soap/java/src/org/apache/soap/AttributeHandler.java,v
retrieving revision 1.3
diff -r1.3 AttributeHandler.java
131a132
>     if ("" == namespaceURI) return null ;
157c158,159
<       nsStack.addNSDeclaration(namespacePrefix, namespaceURI);
---
>       if (namespacePrefix != null)
>         nsStack.addNSDeclaration(namespacePrefix, namespaceURI);
211,212c213,217
<       sink.write(' ' + getPrefixFromURI(attrQName.getNamespaceURI()) +
<                  ':' + attrQName.getLocalPart() + "=\"" +
---
>       sink.write(' ') ;
>       String nsPrefix ;
>       if ((nsPrefix = getPrefixFromURI(attrQName.getNamespaceURI())) != null)
>         sink.write(nsPrefix + ':') ;
>       sink.write(attrQName.getLocalPart() + "=\"" +
Index: src/org/apache/soap/util/xml/QName.java
===================================================================
RCS file: /home/cvspublic/xml-soap/java/src/org/apache/soap/util/xml/QName.java,v
retrieving revision 1.4
diff -r1.4 QName.java
108c108
<     this.namespaceURI = namespaceURI.intern();
---
>     this.namespaceURI = (namespaceURI == null ? "" : namespaceURI).intern();
****************** End patch

    Ryo Neyama @ IBM Research, Tokyo Research Laboratory
    Internet Technology
    neyama@trl.ibm.co.jp
    +81-46-215-4322 (Phone) / +81-46-273-7428 (FAX)

Re: NullPointerException in unmarshalling

Posted by Ryo Neyama <ne...@trl.ibm.co.jp>.
Hi, again.

> A NullPointerException is thrown in unmarshalling an XML in which SOAP
> Body element has "Id" attribute. I'm wondering setting an "Id"
> attribute is allowed according to the schema of SOAP, because SOAP Body
> element allows any attribute.

I was wrong.
"ID" type attribute must be "id" according to the SOAP spec.

> SOAP uses the local, unqualified "id" attribute of type "ID" to
> specify the unique identifier of an encoded element. SOAP uses the
> local, unqualified attribute "href" of type "uri-reference" to specify
> a reference to that value, in a manner conforming to the XML
> Specification [7], XML Schema Specification [11], and XML Linking
> Language Specification [9].

Anyway, the problem is produced by the following code.
I'll try to fix the bug and post a patch.

----- begin
import java.io.*;

import org.w3c.dom.Document ;
import org.apache.soap.Envelope ;
import org.apache.soap.util.xml.XercesParserLiaison ;

public class test {
    public static void main(String[] args) throws Exception {
        String xml ="<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\"><s:Body id=\"body\"></s:Body></s:Envelope>";
        Document dom = new XercesParserLiaison().read("test", new StringReader(xml)) ;
        Envelope.unmarshall(dom.getDocumentElement()) ;
    }
}
----- end

Regards,
    Ryo Neyama @ IBM Research, Tokyo Research Laboratory
    Internet Technology
    neyama@trl.ibm.co.jp

Re: NullPointerException in unmarshalling

Posted by Ryo Neyama <ne...@trl.ibm.co.jp>.
Hi, again.

> A NullPointerException is thrown in unmarshalling an XML in which SOAP
> Body element has "Id" attribute. I'm wondering setting an "Id"
> attribute is allowed according to the schema of SOAP, because SOAP Body
> element allows any attribute.

I was wrong.
"ID" type attribute must be "id" according to the SOAP spec.

> SOAP uses the local, unqualified "id" attribute of type "ID" to
> specify the unique identifier of an encoded element. SOAP uses the
> local, unqualified attribute "href" of type "uri-reference" to specify
> a reference to that value, in a manner conforming to the XML
> Specification [7], XML Schema Specification [11], and XML Linking
> Language Specification [9].

Anyway, the problem is produced by the following code.
I'll try to fix the bug and post a patch.

----- begin
import java.io.*;

import org.w3c.dom.Document ;
import org.apache.soap.Envelope ;
import org.apache.soap.util.xml.XercesParserLiaison ;

public class test {
    public static void main(String[] args) throws Exception {
        String xml ="<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\"><s:Body id=\"body\"></s:Body></s:Envelope>";
        Document dom = new XercesParserLiaison().read("test", new StringReader(xml)) ;
        Envelope.unmarshall(dom.getDocumentElement()) ;
    }
}
----- end

Regards,
    Ryo Neyama @ IBM Research, Tokyo Research Laboratory
    Internet Technology
    neyama@trl.ibm.co.jp