Author: mgrigorov
Date: Wed Oct 26 12:47:23 2011
New Revision: 1189175

URL: http://svn.apache.org/viewvc?rev=1189175&view=rev
Log:
WICKET-4176 The process cannot access the file because it is being used by 
another process

Improve the error handling in case the data file is existing but cannot be 
opened for some reason (e.g. it is locked by another process).


Modified:
    
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/pageStore/DiskDataStore.java

Modified: 
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/pageStore/DiskDataStore.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/main/java/org/apache/wicket/pageStore/DiskDataStore.java?rev=1189175&r1=1189174&r2=1189175&view=diff
==============================================================================
--- 
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/pageStore/DiskDataStore.java
 (original)
+++ 
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/pageStore/DiskDataStore.java
 Wed Oct 26 12:47:23 2011
@@ -326,18 +326,27 @@ public class DiskDataStore implements ID
                                PageWindow window = 
getManager().createPageWindow(pageId, data.length);
 
                                FileChannel channel = getFileChannel(true);
-                               try
-                               {
-                                       // write the content
-                                       channel.write(ByteBuffer.wrap(data), 
window.getFilePartOffset());
-                               }
-                               catch (IOException e)
+                               if (channel != null)
                                {
-                                       log.error("Error writing to a channel " 
+ channel, e);
+                                       try
+                                       {
+                                               // write the content
+                                               
channel.write(ByteBuffer.wrap(data), window.getFilePartOffset());
+                                       }
+                                       catch (IOException e)
+                                       {
+                                               log.error("Error writing to a 
channel " + channel, e);
+                                       }
+                                       finally
+                                       {
+                                               IOUtils.closeQuietly(channel);
+                                       }
                                }
-                               finally
+                               else
                                {
-                                       IOUtils.closeQuietly(channel);
+                                       log.warn(
+                                               "Cannot save page with id '{}' 
because the data file cannot be opened.",
+                                               pageId);
                                }
                        }
                }
@@ -403,7 +412,7 @@ public class DiskDataStore implements ID
                                }
                                catch (FileNotFoundException fnfx)
                                {
-                                       // should not happen. we check 
explicitly earlier
+                                       // can happen if the file is locked. 
WICKET-4176
                                        log.error(fnfx.getMessage(), fnfx);
                                }
                        }


Reply via email to