Commits

Anonymous committed ec3f179

Issue number: CACHE-189 / AbstractDiskPersistenceListener.store hangs on exception
Obtained from: marcel
Submitted by: Lars Torunski

  • Participants
  • Parent commits 53a6f50

Comments (0)

Files changed (1)

src/java/com/opensymphony/oscache/plugins/diskpersistence/AbstractDiskPersistenceListener.java

 
         try {
             fout = new FileOutputStream(file);
-            oout = new ObjectOutputStream(fout);
-            oout.writeObject(obj);
-            oout.flush();
+            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());
-        } finally {
-            try {
-                fout.close();
-            } catch (Exception e) {
-            }
-
-            try {
-                oout.close();
-            } catch (Exception e) {
-            }
         }
     }