[ http://issues.apache.org/jira/browse/XERCESJ-1007?page=all ]

Nathan Beyer updated XERCESJ-1007:
----------------------------------

    Attachment: DOMSerializerImpl_patch.txt

I've created a patch that refactors the reflection code a bit and massages 
Throwables into null values.

I was able to recreate and test the issue. Here's what I did.

* Wrote a little test class that looks as follows:
<snip>
    public void testWriteToString() throws Exception {
        DOMSerializerImpl dsi = new DOMSerializerImpl ();
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = factory.newDocumentBuilder();
        Document document = builder.newDocument();
        String result = dsi.writeToString(document);
        assertNotNull (result);
    }
</snip>
* Setup a Sun 1.4.2_6 JRE and put the 'xml-apis.jar' in the front of the 
bootstrap classpath. This puts the latest W3C classes in the classpath such 
that the latest Document class is used by JAXP.
* Invoked the test class with the latest Xerces JAR in the classpath and passed 
the following VM argument: 
"-Djavax.xml.parsers.DocumentBuilderFactory=org.apache.crimson.jaxp.DocumentBuilderFactoryImpl".
 The VM arg was passed to guarantee that the Crimson parser that comes with the 
JRE is used and NOT Xerces.

Results:
* The original implementation does throw an AbstractMethodError when the 
Method.invoke() is executed.
* I'm guessing that this is because the Crimson implementation was compiled 
against and older version of the Document interface that doesn't implement 
these methods, thus an unimplemented, abstract method is executed.



> AbstractMethodError is not caught in DOMSerializerImpl.writeToString() and ...
> ------------------------------------------------------------------------------
>
>          Key: XERCESJ-1007
>          URL: http://issues.apache.org/jira/browse/XERCESJ-1007
>      Project: Xerces2-J
>         Type: Bug
>   Components: Serialization
>     Versions: 2.6.2
>  Environment: XML-XERCES CVS snapshot as of Sep. 7, 2004
> jdk 1.4.2_04
> windows 2000 sp4
>     Reporter: Yoon Kyung Koo
>  Attachments: DOMSerializerImpl_patch.txt
>
> The DOMSerializerImpl uses reflection to check whether "getXmlVersion" method 
> or "getInputEncoding", ... exists in the Document implementation class of 
> some given dom node in the writeToString(), write(), writeToURI() methods.
> The problem is that when the DOM node is not a Xerces dom node then the 
> checking line can throw an AbstractMethodError and we only catch Exception.
> I think that those "catch (Exception e)" should be changed with "catch 
> (Throwable t)".
> current codes are...
>         // this should run under JDK 1.1.8...
>         try {
>             getXmlVersion =
>                 fDocument.getClass().getMethod("getXmlVersion", new Class[] 
> {});
>             if (getXmlVersion != null) {
>                 ver = (String) getXmlVersion.invoke(fDocument, (Object[]) 
> null);
>             }
>         } catch (Exception e) { <- I think these are problems.
>             // no way to test the version...
>             // ignore the exception
>         }

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


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

Reply via email to