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

Key: CACHE-189
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Lars Torunski
Reporter: marcel
Votes: 0
Watchers: 2
Operations

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

AbstractDiskPersistenceListener.store hangs on exception

Created: 19/Jul/05 03:10 PM   Updated: 25/Sep/05 03:33 AM
Component/s: Listeners
Affects Version/s: 2.1.1
Fix Version/s: 2.2 RC

Environment: Windows XP, Sun JRE 1.5


 Description  « Hide
to reproduce:

put an object in the cache that is not a Serializable
 hangs in store

The code is:

try {
            fout = new FileOutputStream(file);
            oout = new ObjectOutputStream(fout);
            oout.writeObject(obj);
            oout.flush();
        } catch (Exception e) {
            while (file.exists() && !file.delete()) {
                ;
            }

throw new CachePersistenceException("Unable to write '" + file + "' in the cache. Exception: " + e.getClass().getName() + ", Message: " + e.getMessage());
        } finally {
            try {
                oout.close();
            } catch (Exception e) {
            try {
                fout.close();
            } catch (Exception e) {
        }

Problem is that in the catch clause when writeObject throws an exception, the code tries to delete the file that is still opened, which can't succeed (at least on XP/JDK 1.5)
Better:

try {
            fout = new FileOutputStream(file);
            try {
                oout = new ObjectOutputStream(fout);
                try {
                    oout.writeObject(obj);
                    oout.flush();
                } finally {
                    try {
                        oout.close();
                    } catch (Exception e) {
                    }
                }
            } finally {
                try {
                    fout.close();
                } catch (Exception e) {
                }
            }
        } catch (Exception e) {
            while (file.exists() && !file.delete()) {
                ;
            }

throw new CachePersistenceException("Unable to write '" + file + "' in the cache. Exception: " + e.getClass().getName() + ", Message: " + e.getMessage());
        }

fout needs its own finalize&close because ObjectOutputStream() might throw an exception.

 All   Comments   Change History      Sort Order:
Lars Torunski - [09/Sep/05 11:32 AM ]
Fixed in CVS HEAD