r26665 - trunk/freenet/src/freenet/client/async

[email protected]
Newsgroups gmane.network.freenet.cvs
Message-ID <[email protected]>
Author: toad
Date: 2009-04-08 22:54:45 +0000 (Wed, 08 Apr 2009)
New Revision: 26665

Modified:
   trunk/freenet/src/freenet/client/async/SplitFileFetcher.java
Log:
Handle cancelling a nearly finished splitfile without NPEing!


Modified: trunk/freenet/src/freenet/client/async/SplitFileFetcher.java
===================================================================
--- trunk/freenet/src/freenet/client/async/SplitFileFetcher.java	2009-04-08 21:24:03 UTC (rev 26664)
+++ trunk/freenet/src/freenet/client/async/SplitFileFetcher.java	2009-04-08 22:54:45 UTC (rev 26665)
@@ -568,6 +568,15 @@
 		for(int i=0;i<segments.length;i++) {
 			if(logMINOR)
 				Logger.minor(this, "Cancelling segment "+i);
+			if(segments[i] == null) {
+				synchronized(this) {
+					if(finished) {
+						// Not unusual, if some of the later segments are already finished when cancel() is called.
+						if(logMINOR) Logger.minor(this, "Finished mid-cancel on "+this);
+						return;
+					}
+				}
+			}
 			if(persistent)
 				container.activate(segments[i], 1);
 			segments[i].cancel(container, context);
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.