harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Kevin Zhou (JIRA)" <j...@apache.org>
Subject [jira] Commented: (HARMONY-6213) [classlib][beans] XMLDecoder.readObject() should not invoke org.xml.sax.SAXParseException
Date Wed, 27 May 2009 06:26:45 GMT

    [ https://issues.apache.org/jira/browse/HARMONY-6213?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12713439#action_12713439
] 

Kevin Zhou commented on HARMONY-6213:
-------------------------------------

The exceptions are caused by repeated parsing of the given InputStream content in order to
read object. 
Previously, the code is like:
public Object readObject() {
    try {
        SAXParserFactory.newInstance().newSAXParser().parse(inputStream, new SAXHandler());
    } catch (Exception e) {
        this.listener.exceptionThrown(e);
    }

I suggest modify it to:
private SAXHandler saxHandler  = null;
public Object readObject() {
    if(saxHandler  == null) {
        saxHandler = new SAXHandler();
        try {
            SAXParserFactory.newInstance().newSAXParser().parse(inputStream, saxHandler );
        } catch (Exception e) {
            this.listener.exceptionThrown(e);
        }

Thus, it will only parse the inputstream once at the first calling of readObject method.

> [classlib][beans] XMLDecoder.readObject() should not invoke org.xml.sax.SAXParseException
> -----------------------------------------------------------------------------------------
>
>                 Key: HARMONY-6213
>                 URL: https://issues.apache.org/jira/browse/HARMONY-6213
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>    Affects Versions: 5.0M9
>            Reporter: Kevin Zhou
>             Fix For: 5.0M10
>
>   Original Estimate: 24h
>  Remaining Estimate: 24h
>
> Given a test case [1], RI passes it while HARMONY fails. 
> For HARMONY, it throws the following exceptions:
> org.xml.sax.SAXParseException: Premature end of file.
> Continue...
> org.xml.sax.SAXParseException: Premature end of file.
> Continue...
> org.xml.sax.SAXParseException: Premature end of file.
> Continue...
> org.xml.sax.SAXParseException: Premature end of file.
> Continue...
> [1] Test Case:
> public void test_readObject() throws Exception {
>         final Vector<Exception> exceptionList = new Vector<Exception>();
>         final ExceptionListener exceptionListener = new ExceptionListener() {
>             public void exceptionThrown(Exception e) {
>                 exceptionList.addElement(e);
>                 System.err.println(e + "\nContinue...");
>             }
>         };
>         String content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><java version=\"1.6.0_13\"
class=\"java.beans.XMLDecoder\"><int>1</int><int>2</int><int>3</int></java>";
>         XMLDecoder xmlDecoder = new XMLDecoder(new ByteArrayInputStream(content
>                 .getBytes("UTF-8")));
>         xmlDecoder.setExceptionListener(exceptionListener);
>         assertEquals(new Integer(1), xmlDecoder.readObject());
>         assertEquals(new Integer(2), xmlDecoder.readObject());
>         assertEquals(new Integer(3), xmlDecoder.readObject());
>         xmlDecoder.close();
>         assertEquals(0, exceptionList.size());
>     } 

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


Mime
View raw message