null pointer exception on attempt to release lock explicitly.
[vamsas.git] / src / uk / ac / vamsas / client / simpleclient / FileLock.java
index ef29f47..9201702 100644 (file)
@@ -34,10 +34,13 @@ public class FileLock extends Lock {
     try { 
       advisory=new NativeLock(_lock, block);
     } catch (Exception e) {
-      log.fatal("Failed to create advisory lock file "+_lock,e);
-      throw new Error("Failed to create advisory lock file "+_lock);          
+      if (!_lock.exists()) {
+        // advisory cannot be created. this is serious.
+        log.fatal("Failed to create advisory lock file "+_lock,e);
+        throw new Error("Failed to create advisory lock file "+_lock);
+      }
     }
-    return advisory.isLocked();
+    return (advisory!=null) && advisory.isLocked();
   }
   /**
    * call to clear up a filelock file after its been made
@@ -45,9 +48,10 @@ public class FileLock extends Lock {
    */
   private void tidy() {
     if (_lock!=null) { 
-      if ( advisory!=null) 
+      if ( advisory!=null) {
+        advisory.target.deleteOnExit(); // release will null the target
         advisory.release(true);
-      advisory.target.deleteOnExit();
+      }
       advisory=null;
       _lock=null;
     }