You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by rm...@apache.org on 2014/12/22 19:42:28 UTC

svn commit: r1647371 - in /lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/store: MockIndexInputWrapper.java MockIndexOutputWrapper.java

Author: rmuir
Date: Mon Dec 22 18:42:28 2014
New Revision: 1647371

URL: http://svn.apache.org/r1647371
Log:
LUCENE-6125: add more safety checks to MockDirectoryWrapper

Modified:
    lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/store/MockIndexInputWrapper.java
    lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/store/MockIndexOutputWrapper.java

Modified: lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/store/MockIndexInputWrapper.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/store/MockIndexInputWrapper.java?rev=1647371&r1=1647370&r2=1647371&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/store/MockIndexInputWrapper.java (original)
+++ lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/store/MockIndexInputWrapper.java Mon Dec 22 18:42:28 2014
@@ -2,6 +2,7 @@ package org.apache.lucene.store;
 
 import java.io.IOException;
 import java.util.Map;
+import java.util.Set;
 
 /*
  * Licensed to the Apache Software Foundation (ASF) under one or more
@@ -42,12 +43,17 @@ public class MockIndexInputWrapper exten
 
   @Override
   public void close() throws IOException {
+    if (closed) {
+      delegate.close(); // don't mask double-close bugs
+      return;
+    }
+    closed = true;
+    
     try {
       // turn on the following to look for leaks closing inputs,
       // after fixing TestTransactions
       // dir.maybeThrowDeterministicException();
     } finally {
-      closed = true;
       delegate.close();
       // Pending resolution on LUCENE-686 we may want to
       // remove the conditional check so we also track that
@@ -184,6 +190,30 @@ public class MockIndexInputWrapper exten
   }
 
   @Override
+  public int readZInt() throws IOException {
+    ensureOpen();
+    return delegate.readZInt();
+  }
+
+  @Override
+  public long readZLong() throws IOException {
+    ensureOpen();
+    return delegate.readZLong();
+  }
+
+  @Override
+  public Set<String> readStringSet() throws IOException {
+    ensureOpen();
+    return delegate.readStringSet();
+  }
+
+  @Override
+  public void skipBytes(long numBytes) throws IOException {
+    ensureOpen();
+    super.skipBytes(numBytes);
+  }
+
+  @Override
   public String toString() {
     return "MockIndexInputWrapper(" + delegate + ")";
   }

Modified: lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/store/MockIndexOutputWrapper.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/store/MockIndexOutputWrapper.java?rev=1647371&r1=1647370&r2=1647371&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/store/MockIndexOutputWrapper.java (original)
+++ lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/store/MockIndexOutputWrapper.java Mon Dec 22 18:42:28 2014
@@ -88,8 +88,16 @@ public class MockIndexOutputWrapper exte
     }
   }
   
+  private boolean closed;
+  
   @Override
   public void close() throws IOException {
+    if (closed) {
+      delegate.close(); // don't mask double-close bugs
+      return;
+    }
+    closed = true;
+    
     try {
       dir.maybeThrowDeterministicException();
     } finally {
@@ -105,6 +113,12 @@ public class MockIndexOutputWrapper exte
       dir.removeIndexOutput(this, name);
     }
   }
+  
+  private void ensureOpen() {
+    if (closed) {
+      throw new AlreadyClosedException("Already closed: " + this);
+    }
+  }
 
   @Override
   public void writeByte(byte b) throws IOException {
@@ -114,6 +128,7 @@ public class MockIndexOutputWrapper exte
   
   @Override
   public void writeBytes(byte[] b, int offset, int len) throws IOException {
+    ensureOpen();
     checkCrashed();
     checkDiskFull(b, offset, null, len);
     
@@ -143,6 +158,7 @@ public class MockIndexOutputWrapper exte
 
   @Override
   public void copyBytes(DataInput input, long numBytes) throws IOException {
+    ensureOpen();
     checkCrashed();
     checkDiskFull(null, 0, input, numBytes);