[ 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 exceptionList = new Vector(); > final ExceptionListener exceptionListener = new ExceptionListener() { > public void exceptionThrown(Exception e) { > exceptionList.addElement(e); > System.err.println(e + "\nContinue..."); > } > }; > String content = "123"; > 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.