History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: XSTR-244
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Assignee: Unassigned
Reporter: Rob Eden
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
XStream

Exception when close() called twice

Created: 23/Sep/05 01:41 PM   Updated: 07/Aug/06 09:19 PM
Component/s: None
Affects Version/s: None
Fix Version/s: 1.2

File Attachments: 1. Text File patch.txt (4 kb)
2. Text File patch.txt (5 kb)
3. Text File patch.txt (11 kb)
4. Text File XStream.java.patch (0.5 kb)


JDK version and platform: 1.5.0_02 for Macintosh


 Description  « Hide
Calling close() multiple times on an ObjectOutputStream created by calling XStream.createObjectOutputStream(...) results in an ArrayIndexOutOfBoundsException. It should detect that it has already been closed and ignore the call.

Here's a test case that can be put in XStreamTest.java:


    public void testMultipleClose() {
     try {
StringWriter sout = new StringWriter();
ObjectOutputStream oout = xstream.createObjectOutputStream( sout );

oout.writeObject( new Integer( 1 ) );

oout.close();
oout.close();
     }
     catch( Exception ex ) {
ex.printStackTrace();
     fail( ex.toString() );
     }
    }

A patch for the fix is attached.

 All   Comments   Change History      Sort Order: Ascending order - Click to sort in descending order
Guilherme Silveira - 11/Mar/06 12:41 PM
1. test case for two closes without any exception (thats the correct writer behaviour, check javadocs), test case for close+flush --> exception (same comment)
2. changed QuickWriter to be Writer-compliant (same comment)
3. kept PrettyWriter as XStream-compliant (StreamException)
4. kept CompactPrettyWriter as XStream-compliant (StreamException)

Guilherme Silveira - 12/Mar/06 08:20 PM
simpler patch (after reading StringWriter source code and comparing my patch to rob's...)

added behaviour:

1. close twice is ok + testcase
2. close and flush = stream exception + testcase
3. close and write = stream exception + testcase

should 2 and 3 ignore the call (as per rob?)?

flush could be ok as nothing changed
write would give the programmer the idea that the object was written but was actually ignored... probably dangerous.

4. added new streamexception constructor with simple string

Guilherme Silveira - 13/Mar/06 05:14 AM
1. corrected system tests 'catch' blocks
2. drop streamexception string constructor
3. only 'tries' the block where the exception is expected