On 3/15/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
Author: jochen
Date: Thu Mar 15 15:02:46 2007
New Revision: 518770
URL: http://svn.apache.org/viewvc?view=rev&rev=518770
Log:
Made the FileCleaningTracker serializable.
This is required by commons-fileupload, because the
DiskFileItem's may be part of the HTTP session while
still carrying a reference to the tracker.
<snip/>
I think this particular solution is sub-optimal in a couple of aspects:
* The instances aren't really serializable so its a bit of a truth in
advertising infringement
* Its introducing a tighter coupling between the next releases of
[io] and [fileupload], which is fine if we can buy that there is
evidence that the change would be helpful to [io] in isolation.
I think identical behavior (for what this is worth) can be obtained by
reverting this commit and having a transient lazily-initialized
FileCleaningTracker in DiskFileItem, which addresses the two bullets
above, and the NotSerializableExceptions that you may otherwise
witness at container shutdown.
WDYT?
-Rahul
Modified:
jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/FileCleaningTracker.java
jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/FileUtilsCleanDirectoryTestCase.java
Modified:
jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/FileCleaningTracker.java
URL:
http://svn.apache.org/viewvc/jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/FileCleaningTracker.java?view=diff&rev=518770&r1=518769&r2=518770
==============================================================================
---
jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/FileCleaningTracker.java
(original)
+++
jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/FileCleaningTracker.java
Thu Mar 15 15:02:46 2007
@@ -17,6 +17,8 @@
package org.apache.commons.io;
import java.io.File;
+import java.io.ObjectStreamException;
+import java.io.Serializable;
import java.lang.ref.PhantomReference;
import java.lang.ref.ReferenceQueue;
import java.util.Collection;
@@ -40,23 +42,28 @@
* @author Martin Cooper
* @version $Id: FileCleaner.java 490987 2006-12-29 12:11:48Z scolebourne $
*/
-public class FileCleaningTracker {
+public class FileCleaningTracker implements Serializable {
+ /**
+ * UID for serializing instances of this class.
+ */
+ private static final long serialVersionUID = -8153509976492548871L;
+
/**
* Queue of <code>Tracker</code> instances being watched.
*/
- ReferenceQueue /* Tracker */ q = new ReferenceQueue();
+ transient ReferenceQueue /* Tracker */ q = new ReferenceQueue();
/**
* Collection of <code>Tracker</code> instances in existence.
*/
- final Collection /* Tracker */ trackers = new Vector(); // synchronized
+ final transient Collection /* Tracker */ trackers = new Vector(); //
synchronized
/**
* Whether to terminate the thread when the tracking is complete.
*/
- volatile boolean exitWhenFinished = false;
+ transient volatile boolean exitWhenFinished = false;
/**
* The thread that will clean up registered files.
*/
- Thread reaper;
+ transient Thread reaper;
//-----------------------------------------------------------------------
/**
@@ -255,4 +262,14 @@
}
}
+ /**
+ * This method is called when an instance is deserialized.
+ * It replaces the deserialized instance with a new, fresh
+ * instance.
+ * @return A new instance, which hasn't been in use so far.
+ * @throws ObjectStreamException Not actually thrown.
+ */
+ private Object readResolve() throws ObjectStreamException {
+ return new FileCleaningTracker();
+ }
}
Modified:
jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/FileUtilsCleanDirectoryTestCase.java
URL:
http://svn.apache.org/viewvc/jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/FileUtilsCleanDirectoryTestCase.java?view=diff&rev=518770&r1=518769&r2=518770
==============================================================================
---
jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/FileUtilsCleanDirectoryTestCase.java
(original)
+++
jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/FileUtilsCleanDirectoryTestCase.java
Thu Mar 15 15:02:46 2007
@@ -103,7 +103,7 @@
}
public void testThrowsOnNullList() throws Exception {
- if (!chmod(top, 0, false)) {
+ if (System.getProperty("os.name").startsWith("Win") || !chmod(top,
0, false)) {
// test wont work if we can't restrict permissions on the
// directory, so skip it.
return;
@@ -122,7 +122,7 @@
final File file = new File(top, "restricted");
FileUtils.touch(file);
- if (!chmod(top, 500, false)) {
+ if (System.getProperty("os.name").startsWith("Win") || !chmod(top,
500, false)) {
// test wont work if we can't restrict permissions on the
// directory, so skip it.
return;
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]