Author: toad
Date: 2008-07-28 23:43:50 +0000 (Mon, 28 Jul 2008)
New Revision: 21459

Modified:
   branches/db4o/freenet/src/freenet/client/async/InsertCompressor.java
   branches/db4o/freenet/src/freenet/client/async/SingleFileInserter.java
Log:
Really fix Cooo's NPEs i think

Modified: branches/db4o/freenet/src/freenet/client/async/InsertCompressor.java
===================================================================
--- branches/db4o/freenet/src/freenet/client/async/InsertCompressor.java        
2008-07-28 23:32:14 UTC (rev 21458)
+++ branches/db4o/freenet/src/freenet/client/async/InsertCompressor.java        
2008-07-28 23:43:50 UTC (rev 21459)
@@ -55,6 +55,15 @@
                        container.activate(inserter, 1);
                        container.activate(origData, 1);
                }
+               if(origData == null) {
+                       if(inserter == null || inserter.cancelled()) {
+                               container.delete(this);
+                               return; // Inserter was cancelled, we weren't 
told.
+                       } else if(inserter.started()) {
+                               Logger.error(this, "Inserter started already, 
but we are about to attempt to compress the data!");
+                               return; // Already started, no point ... but 
this really shouldn't happen.
+                       }
+               }
                synchronized(this) {
                        // Can happen with the above activation and lazy query 
evaluation.
                        if(scheduled) {

Modified: branches/db4o/freenet/src/freenet/client/async/SingleFileInserter.java
===================================================================
--- branches/db4o/freenet/src/freenet/client/async/SingleFileInserter.java      
2008-07-28 23:32:14 UTC (rev 21458)
+++ branches/db4o/freenet/src/freenet/client/async/SingleFileInserter.java      
2008-07-28 23:43:50 UTC (rev 21459)
@@ -53,6 +53,7 @@
        private final boolean earlyEncode;
        private final boolean persistent;
        private boolean started;
+       private boolean cancelled;

        // A persistent hashCode is helpful in debugging, and also means we can 
put
        // these objects into sets etc when we need to.
@@ -774,8 +775,11 @@
        }

        public void cancel(ObjectContainer container, ClientContext context) {
+               cancelled = true;
                if(freeData)
                        block.free(container);
+               if(persistent)
+                       container.set(this);
        }

        public void schedule(ObjectContainer container, ClientContext context) 
throws InsertException {
@@ -800,4 +804,12 @@
                        ctx.eventProducer.produceEvent(new 
StartedCompressionEvent(i), container, context);
                }
        }
+       
+       boolean cancelled() {
+               return cancelled;
+       }
+       
+       boolean started() {
+               return started;
+       }
 }


Reply via email to