Uploaded image for project: 'Harmony'
  1. Harmony
  2. HARMONY-5831

[classlib][beans] XMLDecoder will throw exception for restrict method type check

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 5.0M6
    • 5.0M6
    • Classlib
    • None
    • Patch Available

    Description

      The java.beans.XMLDecoder gets NoSuchMethodExceptions when method which take java.lang.Object as parameters are invoked with a java.lang.String against an "owner" object. In general, XMLDecoder throws a NoSuchMethodException unless the classes of the arguments match exactly with a method signature.

      xml file:
      <java version='1.6.0' class='java.beans.XMLDecoder'>
      <void property='owner'>
      <void method='get' id='v'>
      <string>key</string>
      </void>
      </void>
      <object idref='v'/>
      </java>

      testcase:

      String expectedValue = "expected value";
      HashMap map = new HashMap();
      map.put("key", expectedValue);

      XMLDecoder decoder = new XMLDecoder(this.getClass().getResourceAsStream(
      "/xml/MockOwner.xml"), map);
      String actualValue = (String) decoder.readObject();
      assertEquals(expectedValue,actualValue);

      stack trace:
      java.lang.NoSuchMethodException: get(java.lang.String)
      at java.lang.Class.findMatchingMethod(Unknown Source)
      at java.lang.Class.getMethod(Unknown Source)
      at java.beans.XMLDecoder$SAXHandler.executeCommon(XMLDecoder.java:336)
      at java.beans.XMLDecoder$SAXHandler.execute(XMLDecoder.java:285)
      at java.beans.XMLDecoder$SAXHandler.endElement(XMLDecoder.java:250)
      at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source)
      at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.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.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
      at org.apache.xerces.jaxp.SAXParserImpl.parse(Unknown Source)
      at javax.xml.parsers.SAXParser.parse(Unknown Source)
      at java.beans.XMLDecoder.<init>(XMLDecoder.java:480)
      at java.beans.XMLDecoder.<init>(XMLDecoder.java:456)
      at DecoderTest.decode(DecoderTest.java:28)
      at DecoderTest.main(DecoderTest.java:108)

      Attachments

        1. Harmony-5831.diff
          15 kB
          Sean Qiu

        Activity

          People

            tony.wu Tony Wu
            qiuxiaox Sean Qiu
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: