XML-RPC
  1. XML-RPC
  2. XMLRPC-154

ClassCastException getting faultCode in XmlResponseParser.addResult

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Invalid
    • Affects Version/s: 3.1
    • Fix Version/s: None
    • Component/s: Source
    • Labels:
      None
    • Environment:
      Windows server 2003

      Description

      In 3.1 XmlRpcResponseParser.addResult(Object), the following unguarded code throws a ClassCastException:

      Integer faultCode = (Integer) map.get("faultCode");

      The server (in this case Bugzilla::WebService::Bug::get_bugs.pm) might be using the wrong type (String) for faultCode , but this exception hides the true error being reported so it would be nice if the code were guarded.

      I'm using binaries from xmlrpc-3.1-bin.tar.gz.

      (As an aside, I can't figure out what Object[] to send to get_bugs: neither Integer nor String works.)

      java.lang.ClassCastException: java.lang.String incompatible with java.lang.Integer
      at org.apache.xmlrpc.parser.XmlRpcResponseParser.addResult(XmlRpcResponseParser.java:58)
      at org.apache.xmlrpc.parser.RecursiveTypeParserImpl.endValueTag(RecursiveTypeParserImpl.java:71)
      at org.apache.xmlrpc.parser.XmlRpcResponseParser.endElement(XmlRpcResponseParser.java:183)
      at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source)
      at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanEndElement(Unknown Source)
      at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
      at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(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.xmlrpc.client.XmlRpcStreamTransport.readResponse(XmlRpcStreamTransport.java:175)
      at org.apache.xmlrpc.client.XmlRpcStreamTransport.sendRequest(XmlRpcStreamTransport.java:145)
      at org.apache.xmlrpc.client.XmlRpcHttpTransport.sendRequest(XmlRpcHttpTransport.java:94)
      at org.apache.xmlrpc.client.XmlRpcSunHttpTransport.sendRequest(XmlRpcSunHttpTransport.java:44)
      at org.apache.xmlrpc.client.XmlRpcClientWorker.execute(XmlRpcClientWorker.java:53)
      at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:166)
      at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:136)
      at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:125)

      Thanks,
      Wes

        Activity

        Hide
        Dmitry Katsubo added a comment -

        Sorry, updated version:

        === cut ===
        — XmlRpcResponseParser.java.orig 2011-06-24 16:12:19.049354800 +0200
        +++ XmlRpcResponseParser.java 2011-06-24 16:41:59.826376700 +0200
        @@ -58,12 +58,16 @@
        super.setResult(pResult);
        } else {
        Map map = (Map) pResult;

        • Integer faultCode = (Integer) map.get("faultCode");
          + Object faultCode = map.get("faultCode");
          if (faultCode == null) { throw new SAXParseException("Missing faultCode", getDocumentLocator()); }

          try {

        • errorCode = faultCode.intValue();
          + if (faultCode instanceof Number) { + errorCode = ((Number) faultCode).intValue(); + }

          else

          { + errorCode = Integer.parseInt(faultCode.toString()); + }

          } catch (NumberFormatException e) {
          throw new SAXParseException("Invalid faultCode: " + faultCode,
          getDocumentLocator());
          === cut ===

        Show
        Dmitry Katsubo added a comment - Sorry, updated version: === cut === — XmlRpcResponseParser.java.orig 2011-06-24 16:12:19.049354800 +0200 +++ XmlRpcResponseParser.java 2011-06-24 16:41:59.826376700 +0200 @@ -58,12 +58,16 @@ super.setResult(pResult); } else { Map map = (Map) pResult; Integer faultCode = (Integer) map.get("faultCode"); + Object faultCode = map.get("faultCode"); if (faultCode == null) { throw new SAXParseException("Missing faultCode", getDocumentLocator()); } try { errorCode = faultCode.intValue(); + if (faultCode instanceof Number) { + errorCode = ((Number) faultCode).intValue(); + } else { + errorCode = Integer.parseInt(faultCode.toString()); + } } catch (NumberFormatException e) { throw new SAXParseException("Invalid faultCode: " + faultCode, getDocumentLocator()); === cut ===
        Hide
        Dmitry Katsubo added a comment -

        Michael, Jochen,

        I have got the same problem when communicating with Perl XMLRPC::Lite server. This post (http://tech.dir.groups.yahoo.com/group/soaplite/message/1326) tells that the problem is in XMLRPC::Lite module, there is even a patch for that (http://forums.sixapart.com/index.php?showtopic=12363#entry59257).

        But what specification do you refer to?

        I have found the following:
        http://www.w3.org/TR/2000/NOTE-SOAP-20000508/#_Toc478383510
        which says "However, instead of integers, they are defined as XML qualified names" and gives an example "Client.Authentication".
        In my case the server returns faultCode="Client", which is string and corresponds to above mentioned spec.

        Another spec (http://www.xmlrpc.com/spec#faults) does not strictly that the type of "faultCode" is int: it provided the example with int value.

        I also believe there is a minor bug in XmlRpcResponseParser.java code: faultCode.intValue() never throws NumberFormatException. The code should be adapted like below (will not throw ClassCastException but more reasonable SAXParseException):

        === cut ===
        — XmlRpcResponseParser.java.orig 2011-06-24 14:35:39.391077200 +0200
        +++ XmlRpcResponseParser.java 2011-06-24 15:15:18.312552200 +0200
        @@ -58,12 +58,12 @@
        super.setResult(pResult);
        } else {
        Map map = (Map) pResult;

        • Integer faultCode = (Integer) map.get("faultCode");
          + String faultCode = (String) map.get("faultCode");
          if (faultCode == null) { throw new SAXParseException("Missing faultCode", getDocumentLocator()); }

          try

          { - errorCode = faultCode.intValue(); + errorCode = Integer.valueOf(faultCode); }

          catch (NumberFormatException e) {
          throw new SAXParseException("Invalid faultCode: " + faultCode,
          getDocumentLocator());
          === cut ===

        Show
        Dmitry Katsubo added a comment - Michael, Jochen, I have got the same problem when communicating with Perl XMLRPC::Lite server. This post ( http://tech.dir.groups.yahoo.com/group/soaplite/message/1326 ) tells that the problem is in XMLRPC::Lite module, there is even a patch for that ( http://forums.sixapart.com/index.php?showtopic=12363#entry59257 ). But what specification do you refer to? I have found the following: http://www.w3.org/TR/2000/NOTE-SOAP-20000508/#_Toc478383510 which says "However, instead of integers, they are defined as XML qualified names" and gives an example "Client.Authentication". In my case the server returns faultCode="Client", which is string and corresponds to above mentioned spec. Another spec ( http://www.xmlrpc.com/spec#faults ) does not strictly that the type of "faultCode" is int: it provided the example with int value. I also believe there is a minor bug in XmlRpcResponseParser.java code: faultCode.intValue() never throws NumberFormatException. The code should be adapted like below (will not throw ClassCastException but more reasonable SAXParseException): === cut === — XmlRpcResponseParser.java.orig 2011-06-24 14:35:39.391077200 +0200 +++ XmlRpcResponseParser.java 2011-06-24 15:15:18.312552200 +0200 @@ -58,12 +58,12 @@ super.setResult(pResult); } else { Map map = (Map) pResult; Integer faultCode = (Integer) map.get("faultCode"); + String faultCode = (String) map.get("faultCode"); if (faultCode == null) { throw new SAXParseException("Missing faultCode", getDocumentLocator()); } try { - errorCode = faultCode.intValue(); + errorCode = Integer.valueOf(faultCode); } catch (NumberFormatException e) { throw new SAXParseException("Invalid faultCode: " + faultCode, getDocumentLocator()); === cut ===
        Hide
        Jochen Wiedmann added a comment -

        Closing issues which have been released.

        Show
        Jochen Wiedmann added a comment - Closing issues which have been released.
        Hide
        Jochen Wiedmann added a comment -

        Must be fixed in Bugzilla code.

        Show
        Jochen Wiedmann added a comment - Must be fixed in Bugzilla code.
        Hide
        Jochen Wiedmann added a comment -

        I think the problem is clearly on Bugzillas side and must be fixed there. I intend to close this issue as INVALID, should no other information pop up.

        Show
        Jochen Wiedmann added a comment - I think the problem is clearly on Bugzillas side and must be fixed there. I intend to close this issue as INVALID, should no other information pop up.
        Hide
        Michael Donohue added a comment -

        I've just filed the bug with bugzilla, not returning an int for the faultCode: https://bugzilla.mozilla.org/show_bug.cgi?id=446327

        The XMLRPC spec says the faultCode is always an int, but bugzilla is returning a string in some cases.

        Show
        Michael Donohue added a comment - I've just filed the bug with bugzilla, not returning an int for the faultCode: https://bugzilla.mozilla.org/show_bug.cgi?id=446327 The XMLRPC spec says the faultCode is always an int, but bugzilla is returning a string in some cases.

          People

          • Assignee:
            Unassigned
            Reporter:
            Wes
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development