throw exception if you muck with a closed indexinput

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1189973 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Muir 2011-10-27 19:54:11 +00:00
parent ff8796e5ef
commit 60079a441f
1 changed files with 23 additions and 0 deletions

View File

@ -30,6 +30,7 @@ public class MockIndexInputWrapper extends IndexInput {
final String name; final String name;
private IndexInput delegate; private IndexInput delegate;
private boolean isClone; private boolean isClone;
private boolean closed;
/** Construct an empty output buffer. */ /** Construct an empty output buffer. */
public MockIndexInputWrapper(MockDirectoryWrapper dir, String name, IndexInput delegate) { public MockIndexInputWrapper(MockDirectoryWrapper dir, String name, IndexInput delegate) {
@ -45,6 +46,7 @@ public class MockIndexInputWrapper extends IndexInput {
// after fixing TestTransactions // after fixing TestTransactions
// dir.maybeThrowDeterministicException(); // dir.maybeThrowDeterministicException();
} finally { } finally {
closed = true;
delegate.close(); delegate.close();
// Pending resolution on LUCENE-686 we may want to // Pending resolution on LUCENE-686 we may want to
// remove the conditional check so we also track that // remove the conditional check so we also track that
@ -55,8 +57,15 @@ public class MockIndexInputWrapper extends IndexInput {
} }
} }
private void ensureOpen() {
if (closed) {
throw new RuntimeException("Abusing closed IndexInput!");
}
}
@Override @Override
public Object clone() { public Object clone() {
ensureOpen();
dir.inputCloneCount.incrementAndGet(); dir.inputCloneCount.incrementAndGet();
IndexInput iiclone = (IndexInput) delegate.clone(); IndexInput iiclone = (IndexInput) delegate.clone();
MockIndexInputWrapper clone = new MockIndexInputWrapper(dir, name, iiclone); MockIndexInputWrapper clone = new MockIndexInputWrapper(dir, name, iiclone);
@ -80,72 +89,86 @@ public class MockIndexInputWrapper extends IndexInput {
@Override @Override
public long getFilePointer() { public long getFilePointer() {
ensureOpen();
return delegate.getFilePointer(); return delegate.getFilePointer();
} }
@Override @Override
public void seek(long pos) throws IOException { public void seek(long pos) throws IOException {
ensureOpen();
delegate.seek(pos); delegate.seek(pos);
} }
@Override @Override
public long length() { public long length() {
ensureOpen();
return delegate.length(); return delegate.length();
} }
@Override @Override
public byte readByte() throws IOException { public byte readByte() throws IOException {
ensureOpen();
return delegate.readByte(); return delegate.readByte();
} }
@Override @Override
public void readBytes(byte[] b, int offset, int len) throws IOException { public void readBytes(byte[] b, int offset, int len) throws IOException {
ensureOpen();
delegate.readBytes(b, offset, len); delegate.readBytes(b, offset, len);
} }
@Override @Override
public void copyBytes(IndexOutput out, long numBytes) throws IOException { public void copyBytes(IndexOutput out, long numBytes) throws IOException {
ensureOpen();
delegate.copyBytes(out, numBytes); delegate.copyBytes(out, numBytes);
} }
@Override @Override
public void readBytes(byte[] b, int offset, int len, boolean useBuffer) public void readBytes(byte[] b, int offset, int len, boolean useBuffer)
throws IOException { throws IOException {
ensureOpen();
delegate.readBytes(b, offset, len, useBuffer); delegate.readBytes(b, offset, len, useBuffer);
} }
@Override @Override
public short readShort() throws IOException { public short readShort() throws IOException {
ensureOpen();
return delegate.readShort(); return delegate.readShort();
} }
@Override @Override
public int readInt() throws IOException { public int readInt() throws IOException {
ensureOpen();
return delegate.readInt(); return delegate.readInt();
} }
@Override @Override
public long readLong() throws IOException { public long readLong() throws IOException {
ensureOpen();
return delegate.readLong(); return delegate.readLong();
} }
@Override @Override
public String readString() throws IOException { public String readString() throws IOException {
ensureOpen();
return delegate.readString(); return delegate.readString();
} }
@Override @Override
public Map<String,String> readStringStringMap() throws IOException { public Map<String,String> readStringStringMap() throws IOException {
ensureOpen();
return delegate.readStringStringMap(); return delegate.readStringStringMap();
} }
@Override @Override
public int readVInt() throws IOException { public int readVInt() throws IOException {
ensureOpen();
return delegate.readVInt(); return delegate.readVInt();
} }
@Override @Override
public long readVLong() throws IOException { public long readVLong() throws IOException {
ensureOpen();
return delegate.readVLong(); return delegate.readVLong();
} }