GP-0 DB exception improvements/cleanup

This commit is contained in:
ghidra1 2023-02-17 22:05:20 -05:00
parent 4b50ba28a9
commit a9f778ddb0
32 changed files with 324 additions and 215 deletions

View file

@ -125,7 +125,8 @@ public class DBTraceMemoryBufferEntry extends DBAnnotatedObject {
return true; return true;
} }
public int setBytes(ByteBuffer buf, int dstOffset, int len, int blockNum) throws IOException { public int setBytes(ByteBuffer buf, int dstOffset, int len, int blockNum)
throws IndexOutOfBoundsException, IOException {
assert isSane(dstOffset, len, blockNum); assert isSane(dstOffset, len, blockNum);
if (compressed) { if (compressed) {
decompress(); decompress();
@ -136,7 +137,8 @@ public class DBTraceMemoryBufferEntry extends DBAnnotatedObject {
return len; return len;
} }
public int getBytes(ByteBuffer buf, int srcOffset, int len, int blockNum) throws IOException { public int getBytes(ByteBuffer buf, int srcOffset, int len, int blockNum)
throws IndexOutOfBoundsException, IOException {
assert isSane(srcOffset, len, blockNum); assert isSane(srcOffset, len, blockNum);
if (compressed) { if (compressed) {
return doGetCompressedBytes(buf, srcOffset, len, blockNum); return doGetCompressedBytes(buf, srcOffset, len, blockNum);
@ -161,7 +163,8 @@ public class DBTraceMemoryBufferEntry extends DBAnnotatedObject {
} }
} }
protected void doGetBlock(int blockNum, byte[] data) throws IOException { protected void doGetBlock(int blockNum, byte[] data)
throws IndexOutOfBoundsException, IOException {
assert isInUse(blockNum); assert isInUse(blockNum);
if (compressed) { if (compressed) {
doGetCompressedBlock(blockNum, data); doGetCompressedBlock(blockNum, data);
@ -180,7 +183,7 @@ public class DBTraceMemoryBufferEntry extends DBAnnotatedObject {
} }
public void copyFrom(int dstBlockNum, DBTraceMemoryBufferEntry srcBuf, int srcBlockNum) public void copyFrom(int dstBlockNum, DBTraceMemoryBufferEntry srcBuf, int srcBlockNum)
throws IOException { throws IndexOutOfBoundsException, IOException {
assert isInUse(dstBlockNum); assert isInUse(dstBlockNum);
if (compressed) { if (compressed) {
decompress(); decompress();
@ -190,7 +193,8 @@ public class DBTraceMemoryBufferEntry extends DBAnnotatedObject {
buffer.put(dstBlockNum << DBTraceMemorySpace.BLOCK_SHIFT, data); buffer.put(dstBlockNum << DBTraceMemorySpace.BLOCK_SHIFT, data);
} }
public int cmpBytes(ByteBuffer buf, int blkOffset, int len, int blockNum) throws IOException { public int cmpBytes(ByteBuffer buf, int blkOffset, int len, int blockNum)
throws IndexOutOfBoundsException, IOException {
assert isSane(blkOffset, len, blockNum); assert isSane(blkOffset, len, blockNum);
if (compressed) { if (compressed) {
return doCmpCompressedBytes(buf, blkOffset, len, blockNum); return doCmpCompressedBytes(buf, blkOffset, len, blockNum);

View file

@ -50,7 +50,7 @@ public class DBBufferInputStream extends InputStream {
} }
@Override @Override
public int read(byte[] b) throws IOException { public int read(byte[] b) throws IndexOutOfBoundsException, IOException {
if (offset == buffer.length()) { if (offset == buffer.length()) {
return -1; return -1;
} }
@ -61,7 +61,7 @@ public class DBBufferInputStream extends InputStream {
} }
@Override @Override
public int read(byte[] b, int off, int len) throws IOException { public int read(byte[] b, int off, int len) throws IndexOutOfBoundsException, IOException {
if (offset == buffer.length()) { if (offset == buffer.length()) {
return -1; return -1;
} }

View file

@ -1091,7 +1091,7 @@ public class MemoryManagerTest extends AbstractGhidraHeadedIntegrationTest {
mem.getBytes(addr(0), b, 9, 50); mem.getBytes(addr(0), b, 9, 50);
fail("Expected exception"); fail("Expected exception");
} }
catch (ArrayIndexOutOfBoundsException e) { catch (IndexOutOfBoundsException e) {
// expected // expected
} }

View file

@ -92,7 +92,7 @@ public class BinaryField extends Field {
} }
@Override @Override
int write(Buffer buf, int offset) throws IOException { int write(Buffer buf, int offset) throws IndexOutOfBoundsException, IOException {
if (data == null) { if (data == null) {
return buf.putInt(offset, -1); return buf.putInt(offset, -1);
} }
@ -101,7 +101,7 @@ public class BinaryField extends Field {
} }
@Override @Override
int read(Buffer buf, int offset) throws IOException { int read(Buffer buf, int offset) throws IndexOutOfBoundsException, IOException {
checkImmutable(); checkImmutable();
int len = buf.getInt(offset); int len = buf.getInt(offset);
offset += 4; offset += 4;
@ -116,7 +116,7 @@ public class BinaryField extends Field {
} }
@Override @Override
int readLength(Buffer buf, int offset) throws IOException { int readLength(Buffer buf, int offset) throws IndexOutOfBoundsException, IOException {
int len = buf.getInt(offset); int len = buf.getInt(offset);
return (len < 0 ? 0 : len) + 4; return (len < 0 ? 0 : len) + 4;
} }

View file

@ -89,19 +89,19 @@ public final class BooleanField extends PrimitiveField {
} }
@Override @Override
int write(Buffer buf, int offset) throws IOException { int write(Buffer buf, int offset) throws IndexOutOfBoundsException, IOException {
return buf.putByte(offset, value); return buf.putByte(offset, value);
} }
@Override @Override
int read(Buffer buf, int offset) throws IOException { int read(Buffer buf, int offset) throws IndexOutOfBoundsException, IOException {
updatingPrimitiveValue(); updatingPrimitiveValue();
value = buf.getByte(offset); value = buf.getByte(offset);
return offset + 1; return offset + 1;
} }
@Override @Override
int readLength(Buffer buf, int offset) throws IOException { int readLength(Buffer buf, int offset) {
return 1; return 1;
} }

View file

@ -41,12 +41,11 @@ public interface Buffer {
* bytes array provided. * bytes array provided.
* @param offset byte offset from start of buffer. * @param offset byte offset from start of buffer.
* @param bytes byte array to store data * @param bytes byte array to store data
* @throws ArrayIndexOutOfBoundsException is thrown if an invalid offset is * @throws IndexOutOfBoundsException is thrown if an invalid offset is specified.
* specified.
* @throws IOException is thrown if an error occurs while accessing the * @throws IOException is thrown if an error occurs while accessing the
* underlying storage. * underlying storage.
*/ */
public void get(int offset, byte[] bytes) throws IOException; public void get(int offset, byte[] bytes) throws IndexOutOfBoundsException, IOException;
/** /**
* Get the byte data located at the specified offset and store into the data * Get the byte data located at the specified offset and store into the data
@ -55,72 +54,71 @@ public interface Buffer {
* @param data byte array to store the data. * @param data byte array to store the data.
* @param dataOffset offset into the data buffer * @param dataOffset offset into the data buffer
* @param length amount of data to read * @param length amount of data to read
* @throws ArrayIndexOutOfBoundsException if an invalid offset, dataOffset, * @throws IndexOutOfBoundsException if an invalid offset, dataOffset, or length is specified.
* or length is specified.
* @throws IOException is thrown if an error occurs while accessing the * @throws IOException is thrown if an error occurs while accessing the
* underlying storage. * underlying storage.
*/ */
public void get(int offset, byte[] data, int dataOffset, int length) throws IOException; public void get(int offset, byte[] data, int dataOffset, int length)
throws IndexOutOfBoundsException, IOException;
/** /**
* Get the byte data located at the specified offset. * Get the byte data located at the specified offset.
* @param offset byte offset from start of buffer. * @param offset byte offset from start of buffer.
* @param length number of bytes to be read and returned * @param length number of bytes to be read and returned
* @return the byte array. * @return the byte array.
* @throws ArrayIndexOutOfBoundsException is thrown if an invalid offset is * @throws IndexOutOfBoundsException is thrown if an invalid offset is
* specified or the end of the buffer was encountered while reading the * specified or the end of the buffer was encountered while reading the
* data. * data.
* @throws IOException is thrown if an error occurs while accessing the * @throws IOException is thrown if an error occurs while accessing the
* underlying storage. * underlying storage.
*/ */
public byte[] get(int offset, int length) throws IOException; public byte[] get(int offset, int length) throws IndexOutOfBoundsException, IOException;
/** /**
* Get the 8-bit byte value located at the specified offset. * Get the 8-bit byte value located at the specified offset.
* @param offset byte offset from start of buffer. * @param offset byte offset from start of buffer.
* @return the byte value at the specified offset. * @return the byte value at the specified offset.
* @throws ArrayIndexOutOfBoundsException is thrown if an invalid offset is * @throws IndexOutOfBoundsException is thrown if an invalid offset is specified.
* specified.
* @throws IOException is thrown if an error occurs while accessing the * @throws IOException is thrown if an error occurs while accessing the
* underlying storage. * underlying storage.
*/ */
public byte getByte(int offset) throws IOException; public byte getByte(int offset) throws IndexOutOfBoundsException, IOException;
/** /**
* Get the 32-bit integer value located at the specified offset. * Get the 32-bit integer value located at the specified offset.
* @param offset byte offset from start of buffer. * @param offset byte offset from start of buffer.
* @return the integer value at the specified offset. * @return the integer value at the specified offset.
* @throws ArrayIndexOutOfBoundsException is thrown if an invalid offset is * @throws IndexOutOfBoundsException is thrown if an invalid offset is
* specified or the end of the buffer was encountered while reading the * specified or the end of the buffer was encountered while reading the
* value. * value.
* @throws IOException is thrown if an error occurs while accessing the * @throws IOException is thrown if an error occurs while accessing the
* underlying storage. * underlying storage.
*/ */
public int getInt(int offset) throws IOException; public int getInt(int offset) throws IndexOutOfBoundsException, IOException;
/** /**
* Get the 16-bit short value located at the specified offset. * Get the 16-bit short value located at the specified offset.
* @param offset byte offset from start of buffer. * @param offset byte offset from start of buffer.
* @return the short value at the specified offset. * @return the short value at the specified offset.
* @throws ArrayIndexOutOfBoundsException is thrown if an invalid offset is * @throws IndexOutOfBoundsException is thrown if an invalid offset is
* specified or the end of the buffer was encountered while reading the * specified or the end of the buffer was encountered while reading the
* value. * value.
* @throws IOException is thrown if an error occurs while accessing the * @throws IOException is thrown if an error occurs while accessing the
* underlying storage. * underlying storage.
*/ */
public short getShort(int offset) throws IOException; public short getShort(int offset) throws IndexOutOfBoundsException, IOException;
/** /**
* Get the 64-bit long value located at the specified offset. * Get the 64-bit long value located at the specified offset.
* @param offset byte offset from start of buffer. * @param offset byte offset from start of buffer.
* @return the long value at the specified offset. * @return the long value at the specified offset.
* @throws ArrayIndexOutOfBoundsException is thrown if an invalid offset is * @throws IndexOutOfBoundsException is thrown if an invalid offset is
* specified or the end of the buffer was encountered while reading the * specified or the end of the buffer was encountered while reading the
* value. * value.
* @throws IOException is thrown if an error occurs while accessing the * @throws IOException is thrown if an error occurs while accessing the
* underlying storage. * underlying storage.
*/ */
public long getLong(int offset) throws IOException; public long getLong(int offset) throws IndexOutOfBoundsException, IOException;
/** /**
* Put a specified number of bytes from the array provided into the buffer * Put a specified number of bytes from the array provided into the buffer
@ -132,12 +130,13 @@ public interface Buffer {
* @param length the number of bytes to be stored. * @param length the number of bytes to be stored.
* @return the next available offset into the buffer, or -1 if the buffer is * @return the next available offset into the buffer, or -1 if the buffer is
* full. * full.
* @throws ArrayIndexOutOfBoundsException if an invalid offset is provided * @throws IndexOutOfBoundsException if an invalid offset is provided
* or the end of buffer was encountered while storing the data. * or the end of buffer was encountered while storing the data.
* @throws IOException is thrown if an error occurs while accessing the * @throws IOException is thrown if an error occurs while accessing the
* underlying storage. * underlying storage.
*/ */
public int put(int offset, byte[] data, int dataOffset, int length) throws IOException; public int put(int offset, byte[] data, int dataOffset, int length)
throws IndexOutOfBoundsException, IOException;
/** /**
* Put the bytes provided into the buffer at the specified offset. The * Put the bytes provided into the buffer at the specified offset. The
@ -147,12 +146,12 @@ public interface Buffer {
* @param bytes the byte data to be stored. * @param bytes the byte data to be stored.
* @return the next available offset into the buffer, or -1 if the buffer is * @return the next available offset into the buffer, or -1 if the buffer is
* full. * full.
* @throws ArrayIndexOutOfBoundsException if an invalid offset is provided * @throws IndexOutOfBoundsException if an invalid offset is provided
* or the end of buffer was encountered while storing the data. * or the end of buffer was encountered while storing the data.
* @throws IOException is thrown if an error occurs while accessing the * @throws IOException is thrown if an error occurs while accessing the
* underlying storage. * underlying storage.
*/ */
public int put(int offset, byte[] bytes) throws IOException; public int put(int offset, byte[] bytes) throws IndexOutOfBoundsException, IOException;
/** /**
* Put the 8-bit byte value into the buffer at the specified offset. * Put the 8-bit byte value into the buffer at the specified offset.
@ -160,11 +159,11 @@ public interface Buffer {
* @param b the byte value to be stored. * @param b the byte value to be stored.
* @return the next available offset into the buffer, or -1 if the buffer is * @return the next available offset into the buffer, or -1 if the buffer is
* full. * full.
* @throws ArrayIndexOutOfBoundsException if an invalid offset is provided. * @throws IndexOutOfBoundsException if an invalid offset is provided.
* @throws IOException is thrown if an error occurs while accessing the * @throws IOException is thrown if an error occurs while accessing the
* underlying storage. * underlying storage.
*/ */
public int putByte(int offset, byte b) throws IOException; public int putByte(int offset, byte b) throws IndexOutOfBoundsException, IOException;
/** /**
* Put the 32-bit integer value into the buffer at the specified offset. * Put the 32-bit integer value into the buffer at the specified offset.
@ -172,12 +171,12 @@ public interface Buffer {
* @param v the integer value to be stored. * @param v the integer value to be stored.
* @return the next available offset into the buffer, or -1 if the buffer is * @return the next available offset into the buffer, or -1 if the buffer is
* full. * full.
* @throws ArrayIndexOutOfBoundsException if an invalid offset is provided * @throws IndexOutOfBoundsException if an invalid offset is provided
* or the end of buffer was encountered while storing the data. * or the end of buffer was encountered while storing the data.
* @throws IOException is thrown if an error occurs while accessing the * @throws IOException is thrown if an error occurs while accessing the
* underlying storage. * underlying storage.
*/ */
public int putInt(int offset, int v) throws IOException; public int putInt(int offset, int v) throws IndexOutOfBoundsException, IOException;
/** /**
* Put the 16-bit short value into the buffer at the specified offset. * Put the 16-bit short value into the buffer at the specified offset.
@ -185,12 +184,12 @@ public interface Buffer {
* @param v the short value to be stored. * @param v the short value to be stored.
* @return the next available offset into the buffer, or -1 if the buffer is * @return the next available offset into the buffer, or -1 if the buffer is
* full. * full.
* @throws ArrayIndexOutOfBoundsException if an invalid offset is provided * @throws IndexOutOfBoundsException if an invalid offset is provided
* or the end of buffer was encountered while storing the data. * or the end of buffer was encountered while storing the data.
* @throws IOException is thrown if an error occurs while accessing the * @throws IOException is thrown if an error occurs while accessing the
* underlying storage. * underlying storage.
*/ */
public int putShort(int offset, short v) throws IOException; public int putShort(int offset, short v) throws IndexOutOfBoundsException, IOException;
/** /**
* Put the 64-bit long value into the buffer at the specified offset. * Put the 64-bit long value into the buffer at the specified offset.
@ -198,11 +197,11 @@ public interface Buffer {
* @param v the long value to be stored. * @param v the long value to be stored.
* @return the next available offset into the buffer, or -1 if the buffer is * @return the next available offset into the buffer, or -1 if the buffer is
* full. * full.
* @throws ArrayIndexOutOfBoundsException if an invalid offset is provided * @throws IndexOutOfBoundsException if an invalid offset is provided
* or the end of buffer was encountered while storing the data. * or the end of buffer was encountered while storing the data.
* @throws IOException is thrown if an error occurs while accessing the * @throws IOException is thrown if an error occurs while accessing the
* underlying storage. * underlying storage.
*/ */
public int putLong(int offset, long v) throws IOException; public int putLong(int offset, long v) throws IndexOutOfBoundsException, IOException;
} }

View file

@ -94,19 +94,19 @@ public final class ByteField extends PrimitiveField {
} }
@Override @Override
int write(Buffer buf, int offset) throws IOException { int write(Buffer buf, int offset) throws IndexOutOfBoundsException, IOException {
return buf.putByte(offset, value); return buf.putByte(offset, value);
} }
@Override @Override
int read(Buffer buf, int offset) throws IOException { int read(Buffer buf, int offset) throws IndexOutOfBoundsException, IOException {
updatingPrimitiveValue(); updatingPrimitiveValue();
value = buf.getByte(offset); value = buf.getByte(offset);
return offset + 1; return offset + 1;
} }
@Override @Override
int readLength(Buffer buf, int offset) throws IOException { int readLength(Buffer buf, int offset) {
return 1; return 1;
} }

View file

@ -338,7 +338,6 @@ public class ChainedBuffer implements Buffer {
* @throws UnsupportedOperationException thrown if this ChainedBuffer utilizes an * @throws UnsupportedOperationException thrown if this ChainedBuffer utilizes an
* Uninitialized Data Source or is read-only * Uninitialized Data Source or is read-only
* @throws IOException thrown if an IO error occurs. * @throws IOException thrown if an IO error occurs.
* @throws UnsupportedOperationException if read-only or uninitialized data source is used
*/ */
public synchronized void setSize(int size, boolean preserveData) throws IOException { public synchronized void setSize(int size, boolean preserveData) throws IOException {
if (readOnly) { if (readOnly) {
@ -595,10 +594,10 @@ public class ChainedBuffer implements Buffer {
* byte within the new buffer. * byte within the new buffer.
* @return the new DBBuffer object. * @return the new DBBuffer object.
* @throws UnsupportedOperationException thrown if this ChainedBuffer is read-only * @throws UnsupportedOperationException thrown if this ChainedBuffer is read-only
* @throws ArrayIndexOutOfBoundsException if offset is invalid. * @throws IndexOutOfBoundsException if offset is invalid.
* @throws IOException thrown if an IO error occurs * @throws IOException thrown if an IO error occurs
*/ */
public synchronized ChainedBuffer split(int offset) throws IOException { public synchronized ChainedBuffer split(int offset) throws IndexOutOfBoundsException, IOException {
if (readOnly) { if (readOnly) {
throw new UnsupportedOperationException("Read-only buffer"); throw new UnsupportedOperationException("Read-only buffer");
} }
@ -606,7 +605,7 @@ public class ChainedBuffer implements Buffer {
throw new AssertException("Invalid Buffer"); throw new AssertException("Invalid Buffer");
} }
if (offset < 0 || offset >= size) { if (offset < 0 || offset >= size) {
throw new ArrayIndexOutOfBoundsException(); throw new IndexOutOfBoundsException();
} }
// Create new DBBuffer // Create new DBBuffer
@ -899,10 +898,11 @@ public class ChainedBuffer implements Buffer {
* @return int actual number of byte read. * @return int actual number of byte read.
* This could be smaller than length if the end of buffer is * This could be smaller than length if the end of buffer is
* encountered while reading data. * encountered while reading data.
* @throws IndexOutOfBoundsException if an invalid offset, dataOffset, or length is specified.
* @throws IOException thrown if IO error occurs * @throws IOException thrown if IO error occurs
*/ */
private int getBytes(int offset, int index, int bufferDataOffset, byte[] data, int dataOffset, private int getBytes(int offset, int index, int bufferDataOffset, byte[] data, int dataOffset,
int length) throws IOException { int length) throws IndexOutOfBoundsException, IOException {
int availableData = dataSpace - bufferDataOffset; int availableData = dataSpace - bufferDataOffset;
int len = availableData < length ? availableData : length; int len = availableData < length ? availableData : length;
int id = dataBufferIdTable[index]; int id = dataBufferIdTable[index];
@ -934,15 +934,15 @@ public class ChainedBuffer implements Buffer {
*/ */
@Override @Override
public synchronized void get(int offset, byte[] data, int dataOffset, int length) public synchronized void get(int offset, byte[] data, int dataOffset, int length)
throws IOException { throws IndexOutOfBoundsException, IOException {
if (dataBufferIdTable == null) { if (dataBufferIdTable == null) {
throw new AssertException("Invalid Buffer"); throw new AssertException("Invalid Buffer");
} }
if (offset < 0 || (offset + length - 1) >= size) { if (offset < 0 || (offset + length - 1) >= size) {
throw new ArrayIndexOutOfBoundsException(); throw new IndexOutOfBoundsException();
} }
if (data.length < dataOffset + length) { if (data.length < dataOffset + length) {
throw new ArrayIndexOutOfBoundsException(); throw new IndexOutOfBoundsException();
} }
int index = offset / dataSpace; int index = offset / dataSpace;
int bufferDataOffset = offset % dataSpace; int bufferDataOffset = offset % dataSpace;
@ -960,7 +960,7 @@ public class ChainedBuffer implements Buffer {
* @see ghidra.framework.store.Buffer#get(int, byte[]) * @see ghidra.framework.store.Buffer#get(int, byte[])
*/ */
@Override @Override
public synchronized void get(int offset, byte[] data) throws IOException { public synchronized void get(int offset, byte[] data) throws IndexOutOfBoundsException, IOException {
get(offset, data, 0, data.length); get(offset, data, 0, data.length);
} }
@ -968,7 +968,7 @@ public class ChainedBuffer implements Buffer {
* @see ghidra.framework.store.Buffer#get(int, int) * @see ghidra.framework.store.Buffer#get(int, int)
*/ */
@Override @Override
public synchronized byte[] get(int offset, int length) throws IOException { public synchronized byte[] get(int offset, int length) throws IndexOutOfBoundsException, IOException {
byte[] data = new byte[length]; byte[] data = new byte[length];
get(offset, data, 0, length); get(offset, data, 0, length);
return data; return data;
@ -978,12 +978,12 @@ public class ChainedBuffer implements Buffer {
* @see ghidra.framework.store.Buffer#getByte(int) * @see ghidra.framework.store.Buffer#getByte(int)
*/ */
@Override @Override
public synchronized byte getByte(int offset) throws IOException { public synchronized byte getByte(int offset) throws IndexOutOfBoundsException, IOException {
if (dataBufferIdTable == null) { if (dataBufferIdTable == null) {
throw new AssertException("Invalid Buffer"); throw new AssertException("Invalid Buffer");
} }
if (offset < 0 || offset >= size) { if (offset < 0 || offset >= size) {
throw new ArrayIndexOutOfBoundsException(); throw new IndexOutOfBoundsException();
} }
int index = offset / dataSpace; int index = offset / dataSpace;
int bufferDataOffset = offset % dataSpace; int bufferDataOffset = offset % dataSpace;
@ -1007,14 +1007,14 @@ public class ChainedBuffer implements Buffer {
* @see ghidra.framework.store.Buffer#getInt(int) * @see ghidra.framework.store.Buffer#getInt(int)
*/ */
@Override @Override
public synchronized int getInt(int offset) throws IOException { public synchronized int getInt(int offset) throws IndexOutOfBoundsException, IOException {
int bufferOffset = dataBaseOffset + (offset % dataSpace); int bufferOffset = dataBaseOffset + (offset % dataSpace);
if (bufferOffset + 3 <= dataSpace) { if (bufferOffset + 3 <= dataSpace) {
if (dataBufferIdTable == null) { if (dataBufferIdTable == null) {
throw new AssertException("Invalid Buffer"); throw new AssertException("Invalid Buffer");
} }
if (offset < 0 || (offset + 3) >= size) { if (offset < 0 || (offset + 3) >= size) {
throw new ArrayIndexOutOfBoundsException(); throw new IndexOutOfBoundsException();
} }
int index = offset / dataSpace; int index = offset / dataSpace;
int id = dataBufferIdTable[index]; int id = dataBufferIdTable[index];
@ -1041,14 +1041,14 @@ public class ChainedBuffer implements Buffer {
* @see ghidra.framework.store.Buffer#getLong(int) * @see ghidra.framework.store.Buffer#getLong(int)
*/ */
@Override @Override
public synchronized long getLong(int offset) throws IOException { public synchronized long getLong(int offset) throws IndexOutOfBoundsException, IOException {
int bufferOffset = dataBaseOffset + (offset % dataSpace); int bufferOffset = dataBaseOffset + (offset % dataSpace);
if (bufferOffset + 7 <= dataSpace) { if (bufferOffset + 7 <= dataSpace) {
if (dataBufferIdTable == null) { if (dataBufferIdTable == null) {
throw new AssertException("Invalid Buffer"); throw new AssertException("Invalid Buffer");
} }
if (offset < 0 || (offset + 7) >= size) { if (offset < 0 || (offset + 7) >= size) {
throw new ArrayIndexOutOfBoundsException(); throw new IndexOutOfBoundsException();
} }
int index = offset / dataSpace; int index = offset / dataSpace;
int id = dataBufferIdTable[index]; int id = dataBufferIdTable[index];
@ -1077,14 +1077,14 @@ public class ChainedBuffer implements Buffer {
* @see ghidra.framework.store.Buffer#getShort(int) * @see ghidra.framework.store.Buffer#getShort(int)
*/ */
@Override @Override
public synchronized short getShort(int offset) throws IOException { public synchronized short getShort(int offset) throws IndexOutOfBoundsException, IOException {
int bufferOffset = dataBaseOffset + (offset % dataSpace); int bufferOffset = dataBaseOffset + (offset % dataSpace);
if (bufferOffset + 1 <= dataSpace) { if (bufferOffset + 1 <= dataSpace) {
if (dataBufferIdTable == null) { if (dataBufferIdTable == null) {
throw new AssertException("Invalid Buffer"); throw new AssertException("Invalid Buffer");
} }
if (offset < 0 || (offset + 1) >= size) { if (offset < 0 || (offset + 1) >= size) {
throw new ArrayIndexOutOfBoundsException(); throw new IndexOutOfBoundsException();
} }
int index = offset / dataSpace; int index = offset / dataSpace;
int id = dataBufferIdTable[index]; int id = dataBufferIdTable[index];
@ -1119,10 +1119,12 @@ public class ChainedBuffer implements Buffer {
* @param startOffset starting offset, inclusive * @param startOffset starting offset, inclusive
* @param endOffset ending offset, inclusive * @param endOffset ending offset, inclusive
* @param fillByte byte value * @param fillByte byte value
* @throws IndexOutOfBoundsException if an invalid offsets are provided
* or the end of buffer was encountered while storing the data.
* @throws IOException thrown if an IO error occurs * @throws IOException thrown if an IO error occurs
*/ */
public synchronized void fill(int startOffset, int endOffset, byte fillByte) public synchronized void fill(int startOffset, int endOffset, byte fillByte)
throws IOException { throws IndexOutOfBoundsException, IOException {
if (readOnly) { if (readOnly) {
throw new UnsupportedOperationException("Read-only buffer"); throw new UnsupportedOperationException("Read-only buffer");
} }
@ -1130,7 +1132,7 @@ public class ChainedBuffer implements Buffer {
throw new IllegalArgumentException(); throw new IllegalArgumentException();
} }
if (startOffset < 0 || endOffset >= size) { if (startOffset < 0 || endOffset >= size) {
throw new ArrayIndexOutOfBoundsException(); throw new IndexOutOfBoundsException();
} }
byte[] fillData = new byte[dataSpace]; byte[] fillData = new byte[dataSpace];
Arrays.fill(fillData, fillByte); Arrays.fill(fillData, fillByte);
@ -1239,7 +1241,7 @@ public class ChainedBuffer implements Buffer {
*/ */
@Override @Override
public synchronized int put(int offset, byte[] data, int dataOffset, int length) public synchronized int put(int offset, byte[] data, int dataOffset, int length)
throws IOException { throws IndexOutOfBoundsException, IOException {
if (readOnly) { if (readOnly) {
throw new UnsupportedOperationException("Read-only buffer"); throw new UnsupportedOperationException("Read-only buffer");
@ -1248,7 +1250,7 @@ public class ChainedBuffer implements Buffer {
throw new AssertException("Invalid Buffer"); throw new AssertException("Invalid Buffer");
} }
if (offset < 0 || (offset + length - 1) >= size) { if (offset < 0 || (offset + length - 1) >= size) {
throw new ArrayIndexOutOfBoundsException(); throw new IndexOutOfBoundsException();
} }
int index = offset / dataSpace; int index = offset / dataSpace;
int bufferDataOffset = offset % dataSpace; int bufferDataOffset = offset % dataSpace;
@ -1275,7 +1277,7 @@ public class ChainedBuffer implements Buffer {
* @see ghidra.framework.store.Buffer#put(int, byte[]) * @see ghidra.framework.store.Buffer#put(int, byte[])
*/ */
@Override @Override
public synchronized int put(int offset, byte[] bytes) throws IOException { public synchronized int put(int offset, byte[] bytes) throws IndexOutOfBoundsException, IOException {
return put(offset, bytes, 0, bytes.length); return put(offset, bytes, 0, bytes.length);
} }
@ -1283,7 +1285,7 @@ public class ChainedBuffer implements Buffer {
* @see ghidra.framework.store.Buffer#putByte(int, byte) * @see ghidra.framework.store.Buffer#putByte(int, byte)
*/ */
@Override @Override
public synchronized int putByte(int offset, byte b) throws IOException { public synchronized int putByte(int offset, byte b) throws IndexOutOfBoundsException, IOException {
if (readOnly) { if (readOnly) {
throw new UnsupportedOperationException("Read-only buffer"); throw new UnsupportedOperationException("Read-only buffer");
} }
@ -1291,7 +1293,7 @@ public class ChainedBuffer implements Buffer {
throw new AssertException("Invalid Buffer"); throw new AssertException("Invalid Buffer");
} }
if (offset < 0 || offset >= size) { if (offset < 0 || offset >= size) {
throw new ArrayIndexOutOfBoundsException(); throw new IndexOutOfBoundsException();
} }
DataBuffer buffer = getBuffer(offset / dataSpace); DataBuffer buffer = getBuffer(offset / dataSpace);
int bufferDataOffset = offset % dataSpace; int bufferDataOffset = offset % dataSpace;
@ -1307,7 +1309,7 @@ public class ChainedBuffer implements Buffer {
* @see ghidra.framework.store.Buffer#putInt(int, int) * @see ghidra.framework.store.Buffer#putInt(int, int)
*/ */
@Override @Override
public synchronized int putInt(int offset, int v) throws IOException { public synchronized int putInt(int offset, int v) throws IndexOutOfBoundsException, IOException {
if (readOnly) { if (readOnly) {
throw new UnsupportedOperationException("Read-only buffer"); throw new UnsupportedOperationException("Read-only buffer");
} }
@ -1317,7 +1319,7 @@ public class ChainedBuffer implements Buffer {
throw new AssertException("Invalid Buffer"); throw new AssertException("Invalid Buffer");
} }
if (offset < 0 || (offset + 3) >= size) { if (offset < 0 || (offset + 3) >= size) {
throw new ArrayIndexOutOfBoundsException(); throw new IndexOutOfBoundsException();
} }
if (useXORMask) { if (useXORMask) {
v = v ^ (int) getXorMask(offset % dataSpace, 4); v = v ^ (int) getXorMask(offset % dataSpace, 4);
@ -1341,7 +1343,7 @@ public class ChainedBuffer implements Buffer {
* @see ghidra.framework.store.Buffer#putLong(int, long) * @see ghidra.framework.store.Buffer#putLong(int, long)
*/ */
@Override @Override
public synchronized int putLong(int offset, long v) throws IOException { public synchronized int putLong(int offset, long v) throws IndexOutOfBoundsException, IOException {
if (readOnly) { if (readOnly) {
throw new UnsupportedOperationException("Read-only buffer"); throw new UnsupportedOperationException("Read-only buffer");
} }
@ -1351,7 +1353,7 @@ public class ChainedBuffer implements Buffer {
throw new AssertException("Invalid Buffer"); throw new AssertException("Invalid Buffer");
} }
if (offset < 0 || (offset + 7) >= size) { if (offset < 0 || (offset + 7) >= size) {
throw new ArrayIndexOutOfBoundsException(); throw new IndexOutOfBoundsException();
} }
if (useXORMask) { if (useXORMask) {
v = v ^ getXorMask(offset % dataSpace, 8); v = v ^ getXorMask(offset % dataSpace, 8);
@ -1376,7 +1378,7 @@ public class ChainedBuffer implements Buffer {
} }
@Override @Override
public synchronized int putShort(int offset, short v) throws IOException { public synchronized int putShort(int offset, short v) throws IndexOutOfBoundsException, IOException {
if (readOnly) { if (readOnly) {
throw new UnsupportedOperationException("Read-only buffer"); throw new UnsupportedOperationException("Read-only buffer");
} }
@ -1386,7 +1388,7 @@ public class ChainedBuffer implements Buffer {
throw new AssertException("Invalid Buffer"); throw new AssertException("Invalid Buffer");
} }
if (offset < 0 || (offset + 1) >= size) { if (offset < 0 || (offset + 1) >= size) {
throw new ArrayIndexOutOfBoundsException(); throw new IndexOutOfBoundsException();
} }
if (useXORMask) { if (useXORMask) {
v = (short) (v ^ (short) getXorMask(offset % dataSpace, 2)); v = (short) (v ^ (short) getXorMask(offset % dataSpace, 2));
@ -1430,7 +1432,7 @@ public class ChainedBuffer implements Buffer {
* @throws IOException thrown if an IO error occurs * @throws IOException thrown if an IO error occurs
*/ */
private void initializeAllocatedBuffer(int chainBufferIndex, DataBuffer buf) private void initializeAllocatedBuffer(int chainBufferIndex, DataBuffer buf)
throws IOException { throws IndexOutOfBoundsException, IOException {
int offset = chainBufferIndex * dataSpace; int offset = chainBufferIndex * dataSpace;
int len = size - offset; int len = size - offset;

View file

@ -43,10 +43,10 @@ public class DBBuffer {
* @param offset the split point. The byte at this offset becomes the first * @param offset the split point. The byte at this offset becomes the first
* byte within the new buffer. * byte within the new buffer.
* @return the new DBBuffer object. * @return the new DBBuffer object.
* @throws ArrayIndexOutOfBoundsException if offset is invalid. * @throws IndexOutOfBoundsException if offset is invalid.
* @throws IOException thrown if an IO error occurs * @throws IOException thrown if an IO error occurs
*/ */
public DBBuffer split(int offset) throws IOException { public DBBuffer split(int offset) throws IndexOutOfBoundsException, IOException {
synchronized (dbh) { synchronized (dbh) {
dbh.checkTransaction(); dbh.checkTransaction();
return new DBBuffer(dbh, buf.split(offset)); return new DBBuffer(dbh, buf.split(offset));
@ -58,6 +58,8 @@ public class DBBuffer {
* @param size new size * @param size new size
* @param preserveData if true, existing data is preserved at the original offsets. If false, * @param preserveData if true, existing data is preserved at the original offsets. If false,
* no additional effort will be expended to preserve data. * no additional effort will be expended to preserve data.
* @throws UnsupportedOperationException thrown if this ChainedBuffer utilizes an
* Uninitialized Data Source or is read-only
* @throws IOException thrown if an IO error occurs. * @throws IOException thrown if an IO error occurs.
*/ */
public void setSize(int size, boolean preserveData) throws IOException { public void setSize(int size, boolean preserveData) throws IOException {
@ -69,7 +71,7 @@ public class DBBuffer {
/** /**
* Returns the length; * Returns the length;
* @return * @return this buffers length
*/ */
public int length() { public int length() {
synchronized (dbh) { synchronized (dbh) {
@ -94,8 +96,12 @@ public class DBBuffer {
* @param startOffset starting offset, inclusive * @param startOffset starting offset, inclusive
* @param endOffset ending offset, exclusive * @param endOffset ending offset, exclusive
* @param fillByte byte value * @param fillByte byte value
* @throws IndexOutOfBoundsException if an invalid offsets are provided
* or the end of buffer was encountered while storing the data.
* @throws IOException thrown if an IO error occurs
*/ */
public void fill(int startOffset, int endOffset, byte fillByte) throws IOException { public void fill(int startOffset, int endOffset, byte fillByte)
throws IndexOutOfBoundsException, IOException {
synchronized (dbh) { synchronized (dbh) {
dbh.checkTransaction(); dbh.checkTransaction();
buf.fill(startOffset, endOffset, fillByte); buf.fill(startOffset, endOffset, fillByte);
@ -107,6 +113,8 @@ public class DBBuffer {
* The size of this buffer increases by the size of dbBuf. When the operation * The size of this buffer increases by the size of dbBuf. When the operation
* is complete, dbBuf object is no longer valid and must not be used. * is complete, dbBuf object is no longer valid and must not be used.
* @param buffer the buffer to be appended to this buffer. * @param buffer the buffer to be appended to this buffer.
* @throws UnsupportedOperationException if read-only, uninitialized data source is used,
* or both buffers do not have the same obfuscation enablement
* @throws IOException thrown if an IO error occurs * @throws IOException thrown if an IO error occurs
*/ */
public void append(DBBuffer buffer) throws IOException { public void append(DBBuffer buffer) throws IOException {
@ -120,13 +128,14 @@ public class DBBuffer {
* Get the 8-bit byte value located at the specified offset. * Get the 8-bit byte value located at the specified offset.
* @param offset byte offset from start of buffer. * @param offset byte offset from start of buffer.
* @return the byte value at the specified offset. * @return the byte value at the specified offset.
* @throws ArrayIndexOutOfBoundsException is thrown if an invalid offset is * @throws IndexOutOfBoundsException is thrown if an invalid offset is
* specified. * specified.
* @throws IOException is thrown if an error occurs while accessing the * @throws IOException is thrown if an error occurs while accessing the
* underlying storage. * underlying storage.
*/ */
public byte getByte(int offset) throws IOException { public byte getByte(int offset) throws IndexOutOfBoundsException, IOException {
synchronized (dbh) { synchronized (dbh) {
dbh.checkIsClosed();
return buf.getByte(offset); return buf.getByte(offset);
} }
} }
@ -138,13 +147,15 @@ public class DBBuffer {
* @param data byte array to store the data. * @param data byte array to store the data.
* @param dataOffset offset into the data buffer * @param dataOffset offset into the data buffer
* @param length amount of data to read * @param length amount of data to read
* @throws ArrayIndexOutOfBoundsException if an invalid offset, dataOffset, * @throws IndexOutOfBoundsException if an invalid offset, dataOffset,
* or length is specified. * or length is specified.
* @throws IOException is thrown if an error occurs while accessing the * @throws IOException is thrown if an error occurs while accessing the
* underlying storage. * underlying storage.
*/ */
public void get(int offset, byte[] data, int dataOffset, int length) throws IOException { public void get(int offset, byte[] data, int dataOffset, int length)
throws IndexOutOfBoundsException, IOException {
synchronized (dbh) { synchronized (dbh) {
dbh.checkIsClosed();
buf.get(offset, data, dataOffset, length); buf.get(offset, data, dataOffset, length);
} }
} }
@ -171,12 +182,13 @@ public class DBBuffer {
* @param bytes the byte data to be stored. * @param bytes the byte data to be stored.
* @param dataOffset the starting offset into the data. * @param dataOffset the starting offset into the data.
* @param length the number of bytes to be stored. * @param length the number of bytes to be stored.
* @throws ArrayIndexOutOfBoundsException if an invalid offset is provided * @throws IndexOutOfBoundsException if an invalid offset is provided
* or the end of buffer was encountered while storing the data. * or the end of buffer was encountered while storing the data.
* @throws IOException is thrown if an error occurs while accessing the * @throws IOException is thrown if an error occurs while accessing the
* underlying storage. * underlying storage.
*/ */
public void put(int offset, byte[] bytes, int dataOffset, int length) throws IOException { public void put(int offset, byte[] bytes, int dataOffset, int length)
throws IndexOutOfBoundsException, IOException {
synchronized (dbh) { synchronized (dbh) {
dbh.checkTransaction(); dbh.checkTransaction();
buf.put(offset, bytes, dataOffset, length); buf.put(offset, bytes, dataOffset, length);
@ -190,12 +202,12 @@ public class DBBuffer {
* array. * array.
* @param offset byte offset from start of buffer. * @param offset byte offset from start of buffer.
* @param bytes the byte data to be stored. * @param bytes the byte data to be stored.
* @throws ArrayIndexOutOfBoundsException if an invalid offset is provided * @throws IndexOutOfBoundsException if an invalid offset is provided
* or the end of buffer was encountered while storing the data. * or the end of buffer was encountered while storing the data.
* @throws IOException is thrown if an error occurs while accessing the * @throws IOException is thrown if an error occurs while accessing the
* underlying storage. * underlying storage.
*/ */
public void put(int offset, byte[] bytes) throws IOException { public void put(int offset, byte[] bytes) throws IndexOutOfBoundsException, IOException {
synchronized (dbh) { synchronized (dbh) {
dbh.checkTransaction(); dbh.checkTransaction();
buf.put(offset, bytes); buf.put(offset, bytes);
@ -206,11 +218,11 @@ public class DBBuffer {
* Put the 8-bit byte value into the buffer at the specified offset. * Put the 8-bit byte value into the buffer at the specified offset.
* @param offset byte offset from start of buffer. * @param offset byte offset from start of buffer.
* @param b the byte value to be stored. * @param b the byte value to be stored.
* @throws ArrayIndexOutOfBoundsException if an invalid offset is provided. * @throws IndexOutOfBoundsException if an invalid offset is provided.
* @throws IOException is thrown if an error occurs while accessing the * @throws IOException is thrown if an error occurs while accessing the
* underlying storage. * underlying storage.
*/ */
public void putByte(int offset, byte b) throws IOException { public void putByte(int offset, byte b) throws IndexOutOfBoundsException, IOException {
synchronized (dbh) { synchronized (dbh) {
dbh.checkTransaction(); dbh.checkTransaction();
buf.putByte(offset, b); buf.putByte(offset, b);
@ -220,21 +232,25 @@ public class DBBuffer {
/** /**
* Get the byte data located at the specified offset. * Get the byte data located at the specified offset.
* @param offset byte offset from start of buffer. * @param offset byte offset from start of buffer.
* @throws ArrayIndexOutOfBoundsException is thrown if an invalid offset is * @param data data buffer to be filled
* @throws IndexOutOfBoundsException is thrown if an invalid offset is
* specified or the end of the buffer was encountered while reading the * specified or the end of the buffer was encountered while reading the
* data. * data.
* @throws IOException is thrown if an error occurs while accessing the * @throws IOException is thrown if an error occurs while accessing the
* underlying storage. * underlying storage.
*/ */
public void get(int offset, byte[] data) throws IOException { public void get(int offset, byte[] data) throws IndexOutOfBoundsException, IOException {
synchronized (dbh) { synchronized (dbh) {
dbh.checkIsClosed();
buf.get(offset, data); buf.get(offset, data);
} }
} }
/** /**
* Delete and release all underlying DataBuffers. * Delete and release all underlying DataBuffers.
* @throws IOException is thrown if an error occurs while accessing the
* underlying storage.
*/ */
public void delete() throws IOException { public void delete() throws IOException {
synchronized (dbh) { synchronized (dbh) {

View file

@ -242,7 +242,7 @@ public class DBHandle {
databaseId = ((long) dbParms.get(DBParms.DATABASE_ID_HIGH_PARM) << 32) + databaseId = ((long) dbParms.get(DBParms.DATABASE_ID_HIGH_PARM) << 32) +
(dbParms.get(DBParms.DATABASE_ID_LOW_PARM) & 0x0ffffffffL); (dbParms.get(DBParms.DATABASE_ID_LOW_PARM) & 0x0ffffffffL);
} }
catch (ArrayIndexOutOfBoundsException e) { catch (IndexOutOfBoundsException e) {
// DBParams is still at version 1 // DBParams is still at version 1
} }
} }
@ -406,6 +406,16 @@ public class DBHandle {
} }
} }
/**
* Check if the database is closed.
* @throws ClosedException if database is closed and further operations are unsupported
*/
public void checkIsClosed() throws ClosedException {
if (isClosed()) {
throw new ClosedException();
}
}
/** /**
* @return true if transaction is currently active * @return true if transaction is currently active
*/ */
@ -418,6 +428,9 @@ public class DBHandle {
* @return transaction ID * @return transaction ID
*/ */
public synchronized long startTransaction() { public synchronized long startTransaction() {
if (isClosed()) {
throw new IllegalStateException("Database is closed");
}
if (txStarted) { if (txStarted) {
throw new IllegalStateException("Transaction already started"); throw new IllegalStateException("Transaction already started");
} }
@ -802,6 +815,8 @@ public class DBHandle {
public synchronized void saveAs(File file, boolean associateWithNewFile, TaskMonitor monitor) public synchronized void saveAs(File file, boolean associateWithNewFile, TaskMonitor monitor)
throws IOException, CancelledException { throws IOException, CancelledException {
checkIsClosed();
if (file.exists()) { if (file.exists()) {
throw new DuplicateFileException("File already exists: " + file); throw new DuplicateFileException("File already exists: " + file);
} }
@ -861,6 +876,7 @@ public class DBHandle {
* @throws IOException if an I/O error occurs while getting the buffer. * @throws IOException if an I/O error occurs while getting the buffer.
*/ */
public DBBuffer getBuffer(int id) throws IOException { public DBBuffer getBuffer(int id) throws IOException {
checkIsClosed();
return new DBBuffer(this, new ChainedBuffer(bufferMgr, id)); return new DBBuffer(this, new ChainedBuffer(bufferMgr, id));
} }
@ -876,6 +892,7 @@ public class DBHandle {
* @throws IOException if an I/O error occurs while getting the buffer. * @throws IOException if an I/O error occurs while getting the buffer.
*/ */
public DBBuffer getBuffer(int id, DBBuffer shadowBuffer) throws IOException { public DBBuffer getBuffer(int id, DBBuffer shadowBuffer) throws IOException {
checkIsClosed();
return new DBBuffer(this, new ChainedBuffer(bufferMgr, id, shadowBuffer.buf, 0)); return new DBBuffer(this, new ChainedBuffer(bufferMgr, id, shadowBuffer.buf, 0));
} }
@ -1071,6 +1088,9 @@ public class DBHandle {
* @return number of buffer cache hits * @return number of buffer cache hits
*/ */
public long getCacheHits() { public long getCacheHits() {
if (bufferMgr == null) {
throw new IllegalStateException("Database is closed");
}
return bufferMgr.getCacheHits(); return bufferMgr.getCacheHits();
} }
@ -1078,6 +1098,9 @@ public class DBHandle {
* @return number of buffer cache misses * @return number of buffer cache misses
*/ */
public long getCacheMisses() { public long getCacheMisses() {
if (bufferMgr == null) {
throw new IllegalStateException("Database is closed");
}
return bufferMgr.getCacheMisses(); return bufferMgr.getCacheMisses();
} }
@ -1085,6 +1108,9 @@ public class DBHandle {
* @return low water mark (minimum buffer pool size) * @return low water mark (minimum buffer pool size)
*/ */
public int getLowBufferCount() { public int getLowBufferCount() {
if (bufferMgr == null) {
throw new IllegalStateException("Database is closed");
}
return bufferMgr.getLowBufferCount(); return bufferMgr.getLowBufferCount();
} }
@ -1102,6 +1128,9 @@ public class DBHandle {
* @return buffer size utilized by this database * @return buffer size utilized by this database
*/ */
public int getBufferSize() { public int getBufferSize() {
if (bufferMgr == null) {
throw new IllegalStateException("Database is closed");
}
return bufferMgr.getBufferSize(); return bufferMgr.getBufferSize();
} }

View file

@ -1,6 +1,5 @@
/* ### /* ###
* IP: GHIDRA * IP: GHIDRA
* REVIEWED: YES
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -16,14 +15,13 @@
*/ */
package db; package db;
import ghidra.util.datastruct.IntIntHashtable;
import ghidra.util.exception.AssertException;
import ghidra.util.exception.NoValueException;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import db.buffers.*; import db.buffers.*;
import ghidra.util.datastruct.IntIntHashtable;
import ghidra.util.exception.AssertException;
import ghidra.util.exception.NoValueException;
/** /**
* <code>DBParms</code> manages 4-byte integer parameters associated with a database * <code>DBParms</code> manages 4-byte integer parameters associated with a database
@ -123,7 +121,7 @@ class DBParms {
private static void storeParm(int parm, int value, DataBuffer buffer) { private static void storeParm(int parm, int value, DataBuffer buffer) {
int maxParmCnt = (buffer.length() - PARM_BASE_OFFSET) / 4; int maxParmCnt = (buffer.length() - PARM_BASE_OFFSET) / 4;
if (parm < 0 || parm >= maxParmCnt) { if (parm < 0 || parm >= maxParmCnt) {
throw new ArrayIndexOutOfBoundsException("Invalid parameter index: " + parm); throw new IndexOutOfBoundsException("Invalid parameter index: " + parm);
} }
int size = (buffer.getInt(DATA_LENGTH_OFFSET) - VERSION_SIZE) / 4; int size = (buffer.getInt(DATA_LENGTH_OFFSET) - VERSION_SIZE) / 4;
if (parm >= size) { if (parm >= size) {
@ -164,15 +162,15 @@ class DBParms {
* @param parm parameter number * @param parm parameter number
* @return parameter value * @return parameter value
* @throws IOException thrown if an IO error occurs * @throws IOException thrown if an IO error occurs
* @throws ArrayIndexOutOfBoundsException if index outside of allocated * @throws IndexOutOfBoundsException if index outside of allocated
* parameter space. * parameter space.
*/ */
int get(int parm) throws IOException, ArrayIndexOutOfBoundsException { int get(int parm) throws IOException, IndexOutOfBoundsException {
try { try {
return cache.get(parm); return cache.get(parm);
} }
catch (NoValueException e) { catch (NoValueException e) {
throw new ArrayIndexOutOfBoundsException(); throw new IndexOutOfBoundsException();
} }
} }

View file

@ -162,7 +162,7 @@ public class DBRecord implements Comparable<DBRecord> {
* Get a copy of the specified field value. * Get a copy of the specified field value.
* @param columnIndex field index * @param columnIndex field index
* @return Field field value * @return Field field value
* @throws ArrayIndexOutOfBoundsException if invalid columnIndex is specified * @throws IndexOutOfBoundsException if invalid columnIndex is specified
*/ */
public Field getFieldValue(int columnIndex) { public Field getFieldValue(int columnIndex) {
Field f = fieldValues[columnIndex]; Field f = fieldValues[columnIndex];
@ -173,7 +173,7 @@ public class DBRecord implements Comparable<DBRecord> {
* Set the field value for the specified field. * Set the field value for the specified field.
* @param colIndex field index * @param colIndex field index
* @param value field value (null permitted for sparse column only) * @param value field value (null permitted for sparse column only)
* @throws ArrayIndexOutOfBoundsException if invalid columnIndex is specified * @throws IndexOutOfBoundsException if invalid columnIndex is specified
* @throws IllegalArgumentException if value type does not match column field type. * @throws IllegalArgumentException if value type does not match column field type.
*/ */
public void setField(int colIndex, Field value) { public void setField(int colIndex, Field value) {
@ -189,7 +189,7 @@ public class DBRecord implements Comparable<DBRecord> {
* modified. * modified.
* @param columnIndex field index * @param columnIndex field index
* @return Field * @return Field
* @throws ArrayIndexOutOfBoundsException if invalid columnIndex is specified * @throws IndexOutOfBoundsException if invalid columnIndex is specified
*/ */
Field getField(int columnIndex) { Field getField(int columnIndex) {
return fieldValues[columnIndex]; return fieldValues[columnIndex];
@ -210,7 +210,7 @@ public class DBRecord implements Comparable<DBRecord> {
* @param columnIndex field index * @param columnIndex field index
* @param field field value to compare with * @param field field value to compare with
* @return true if the fields are equal, else false. * @return true if the fields are equal, else false.
* @throws ArrayIndexOutOfBoundsException if invalid columnIndex is specified * @throws IndexOutOfBoundsException if invalid columnIndex is specified
*/ */
public boolean fieldEquals(int columnIndex, Field field) { public boolean fieldEquals(int columnIndex, Field field) {
return fieldValues[columnIndex].equals(field); return fieldValues[columnIndex].equals(field);
@ -223,7 +223,7 @@ public class DBRecord implements Comparable<DBRecord> {
* @return 0 if equals, a negative number if this record's field is less * @return 0 if equals, a negative number if this record's field is less
* than the specified value, or a positive number if this record's field is * than the specified value, or a positive number if this record's field is
* greater than the specified value. * greater than the specified value.
* @throws ArrayIndexOutOfBoundsException if invalid columnIndex is specified * @throws IndexOutOfBoundsException if invalid columnIndex is specified
*/ */
public int compareFieldTo(int columnIndex, Field value) { public int compareFieldTo(int columnIndex, Field value) {
return fieldValues[columnIndex].compareTo(value); return fieldValues[columnIndex].compareTo(value);
@ -270,7 +270,7 @@ public class DBRecord implements Comparable<DBRecord> {
* Get the long value for the specified field. * Get the long value for the specified field.
* @param colIndex field index * @param colIndex field index
* @return field value * @return field value
* @throws ArrayIndexOutOfBoundsException if invalid columnIndex is specified * @throws IndexOutOfBoundsException if invalid columnIndex is specified
* @throws IllegalFieldAccessException if field does support long data access * @throws IllegalFieldAccessException if field does support long data access
*/ */
public long getLongValue(int colIndex) { public long getLongValue(int colIndex) {
@ -281,7 +281,7 @@ public class DBRecord implements Comparable<DBRecord> {
* Set the long value for the specified field. * Set the long value for the specified field.
* @param colIndex field index * @param colIndex field index
* @param value field value * @param value field value
* @throws ArrayIndexOutOfBoundsException if invalid columnIndex is specified * @throws IndexOutOfBoundsException if invalid columnIndex is specified
* @throws IllegalFieldAccessException if field does support long data access * @throws IllegalFieldAccessException if field does support long data access
*/ */
public void setLongValue(int colIndex, long value) { public void setLongValue(int colIndex, long value) {
@ -293,7 +293,7 @@ public class DBRecord implements Comparable<DBRecord> {
* Get the integer value for the specified field. * Get the integer value for the specified field.
* @param colIndex field index * @param colIndex field index
* @return field value * @return field value
* @throws ArrayIndexOutOfBoundsException if invalid columnIndex is specified * @throws IndexOutOfBoundsException if invalid columnIndex is specified
* @throws IllegalFieldAccessException if field does support integer data access * @throws IllegalFieldAccessException if field does support integer data access
*/ */
public int getIntValue(int colIndex) { public int getIntValue(int colIndex) {
@ -304,7 +304,7 @@ public class DBRecord implements Comparable<DBRecord> {
* Set the integer value for the specified field. * Set the integer value for the specified field.
* @param colIndex field index * @param colIndex field index
* @param value field value * @param value field value
* @throws ArrayIndexOutOfBoundsException if invalid columnIndex is specified * @throws IndexOutOfBoundsException if invalid columnIndex is specified
* @throws IllegalFieldAccessException if field does support integer data access * @throws IllegalFieldAccessException if field does support integer data access
*/ */
public void setIntValue(int colIndex, int value) { public void setIntValue(int colIndex, int value) {
@ -316,7 +316,7 @@ public class DBRecord implements Comparable<DBRecord> {
* Get the short value for the specified field. * Get the short value for the specified field.
* @param colIndex field index * @param colIndex field index
* @return field value * @return field value
* @throws ArrayIndexOutOfBoundsException if invalid columnIndex is specified * @throws IndexOutOfBoundsException if invalid columnIndex is specified
* @throws IllegalFieldAccessException if field does support short data access * @throws IllegalFieldAccessException if field does support short data access
*/ */
public short getShortValue(int colIndex) { public short getShortValue(int colIndex) {
@ -327,7 +327,7 @@ public class DBRecord implements Comparable<DBRecord> {
* Set the short value for the specified field. * Set the short value for the specified field.
* @param colIndex field index * @param colIndex field index
* @param value field value * @param value field value
* @throws ArrayIndexOutOfBoundsException if invalid columnIndex is specified * @throws IndexOutOfBoundsException if invalid columnIndex is specified
* @throws IllegalFieldAccessException if field does support short data access * @throws IllegalFieldAccessException if field does support short data access
*/ */
public void setShortValue(int colIndex, short value) { public void setShortValue(int colIndex, short value) {
@ -339,7 +339,7 @@ public class DBRecord implements Comparable<DBRecord> {
* Get the byte value for the specified field. * Get the byte value for the specified field.
* @param colIndex field index * @param colIndex field index
* @return field value * @return field value
* @throws ArrayIndexOutOfBoundsException if invalid columnIndex is specified * @throws IndexOutOfBoundsException if invalid columnIndex is specified
* @throws IllegalFieldAccessException if field does support byte data access * @throws IllegalFieldAccessException if field does support byte data access
*/ */
public byte getByteValue(int colIndex) { public byte getByteValue(int colIndex) {
@ -350,7 +350,7 @@ public class DBRecord implements Comparable<DBRecord> {
* Set the byte value for the specified field. * Set the byte value for the specified field.
* @param colIndex field index * @param colIndex field index
* @param value field value * @param value field value
* @throws ArrayIndexOutOfBoundsException if invalid columnIndex is specified * @throws IndexOutOfBoundsException if invalid columnIndex is specified
* @throws IllegalFieldAccessException if field does support byte data access * @throws IllegalFieldAccessException if field does support byte data access
*/ */
public void setByteValue(int colIndex, byte value) { public void setByteValue(int colIndex, byte value) {
@ -362,7 +362,7 @@ public class DBRecord implements Comparable<DBRecord> {
* Get the boolean value for the specified field. * Get the boolean value for the specified field.
* @param colIndex field index * @param colIndex field index
* @return field value * @return field value
* @throws ArrayIndexOutOfBoundsException if invalid columnIndex is specified * @throws IndexOutOfBoundsException if invalid columnIndex is specified
* @throws IllegalFieldAccessException if field does support boolean data access * @throws IllegalFieldAccessException if field does support boolean data access
*/ */
public boolean getBooleanValue(int colIndex) { public boolean getBooleanValue(int colIndex) {
@ -373,7 +373,7 @@ public class DBRecord implements Comparable<DBRecord> {
* Set the boolean value for the specified field. * Set the boolean value for the specified field.
* @param colIndex field index * @param colIndex field index
* @param value field value * @param value field value
* @throws ArrayIndexOutOfBoundsException if invalid columnIndex is specified * @throws IndexOutOfBoundsException if invalid columnIndex is specified
* @throws IllegalFieldAccessException if field does support boolean data access * @throws IllegalFieldAccessException if field does support boolean data access
*/ */
public void setBooleanValue(int colIndex, boolean value) { public void setBooleanValue(int colIndex, boolean value) {
@ -385,7 +385,7 @@ public class DBRecord implements Comparable<DBRecord> {
* Get the binary data array for the specified field. * Get the binary data array for the specified field.
* @param colIndex field index * @param colIndex field index
* @return field data * @return field data
* @throws ArrayIndexOutOfBoundsException if invalid columnIndex is specified * @throws IndexOutOfBoundsException if invalid columnIndex is specified
* @throws IllegalFieldAccessException if field does support binary data access * @throws IllegalFieldAccessException if field does support binary data access
*/ */
public byte[] getBinaryData(int colIndex) { public byte[] getBinaryData(int colIndex) {
@ -396,7 +396,7 @@ public class DBRecord implements Comparable<DBRecord> {
* Set the binary data array for the specified field. * Set the binary data array for the specified field.
* @param colIndex field index * @param colIndex field index
* @param bytes field value * @param bytes field value
* @throws ArrayIndexOutOfBoundsException if invalid columnIndex is specified * @throws IndexOutOfBoundsException if invalid columnIndex is specified
* @throws IllegalFieldAccessException if field does support binary data access * @throws IllegalFieldAccessException if field does support binary data access
* or incorrect number of bytes provided * or incorrect number of bytes provided
*/ */
@ -413,7 +413,7 @@ public class DBRecord implements Comparable<DBRecord> {
* Set the field to a null state. For a non-sparse fixed-length column field this will * Set the field to a null state. For a non-sparse fixed-length column field this will
* set the the value to zero and the null state will not be persisted when stored. * set the the value to zero and the null state will not be persisted when stored.
* @param colIndex field index * @param colIndex field index
* @throws ArrayIndexOutOfBoundsException if invalid columnIndex is specified * @throws IndexOutOfBoundsException if invalid columnIndex is specified
*/ */
public void setNull(int colIndex) { public void setNull(int colIndex) {
dirty = true; dirty = true;
@ -428,7 +428,7 @@ public class DBRecord implements Comparable<DBRecord> {
* Get the string value for the specified field. * Get the string value for the specified field.
* @param colIndex field index * @param colIndex field index
* @return field data * @return field data
* @throws ArrayIndexOutOfBoundsException if invalid columnIndex is specified * @throws IndexOutOfBoundsException if invalid columnIndex is specified
* @throws IllegalFieldAccessException if field does support string data access * @throws IllegalFieldAccessException if field does support string data access
*/ */
public String getString(int colIndex) { public String getString(int colIndex) {
@ -439,7 +439,7 @@ public class DBRecord implements Comparable<DBRecord> {
* Set the string value for the specified field. * Set the string value for the specified field.
* @param colIndex field index * @param colIndex field index
* @param str field value * @param str field value
* @throws ArrayIndexOutOfBoundsException if invalid columnIndex is specified * @throws IndexOutOfBoundsException if invalid columnIndex is specified
* @throws IllegalFieldAccessException if field does support string data access * @throws IllegalFieldAccessException if field does support string data access
*/ */
public void setString(int colIndex, String str) { public void setString(int colIndex, String str) {
@ -452,9 +452,10 @@ public class DBRecord implements Comparable<DBRecord> {
* Write the record fields to the specified buffer and offset. * Write the record fields to the specified buffer and offset.
* @param buf data buffer * @param buf data buffer
* @param offset buffer offset * @param offset buffer offset
* @throws IndexOutOfBoundsException if invalid offset is specified
* @throws IOException thrown if IO error occurs * @throws IOException thrown if IO error occurs
*/ */
public void write(Buffer buf, int offset) throws IOException { public void write(Buffer buf, int offset) throws IndexOutOfBoundsException, IOException {
for (Field fieldValue : fieldValues) { for (Field fieldValue : fieldValues) {
offset = fieldValue.write(buf, offset); offset = fieldValue.write(buf, offset);
} }
@ -465,9 +466,10 @@ public class DBRecord implements Comparable<DBRecord> {
* Read the record field data from the specified buffer and offset * Read the record field data from the specified buffer and offset
* @param buf data buffer * @param buf data buffer
* @param offset buffer offset * @param offset buffer offset
* @throws IndexOutOfBoundsException if invalid offset is specified
* @throws IOException thrown if IO error occurs * @throws IOException thrown if IO error occurs
*/ */
public void read(Buffer buf, int offset) throws IOException { public void read(Buffer buf, int offset) throws IndexOutOfBoundsException, IOException {
for (Field fieldValue : fieldValues) { for (Field fieldValue : fieldValues) {
offset = fieldValue.read(buf, offset); offset = fieldValue.read(buf, offset);
} }

View file

@ -347,9 +347,10 @@ public abstract class Field implements Comparable<Field> {
* @param buf data buffer * @param buf data buffer
* @param offset data offset * @param offset data offset
* @return next available Field offset within buffer, or -1 if end of buffer reached. * @return next available Field offset within buffer, or -1 if end of buffer reached.
* @throws IndexOutOfBoundsException if invalid offset is specified
* @throws IOException thrown if IO error occurs * @throws IOException thrown if IO error occurs
*/ */
abstract int write(Buffer buf, int offset) throws IOException; abstract int write(Buffer buf, int offset) throws IndexOutOfBoundsException, IOException;
/** /**
* Read the field value from buf at the specified offset. When reading variable length * Read the field value from buf at the specified offset. When reading variable length
@ -357,9 +358,10 @@ public abstract class Field implements Comparable<Field> {
* @param buf data buffer * @param buf data buffer
* @param offset data offset * @param offset data offset
* @return next Field offset within buffer, or -1 if end of buffer reached. * @return next Field offset within buffer, or -1 if end of buffer reached.
* @throws IndexOutOfBoundsException if invalid offset is specified
* @throws IOException thrown if IO error occurs * @throws IOException thrown if IO error occurs
*/ */
abstract int read(Buffer buf, int offset) throws IOException; abstract int read(Buffer buf, int offset) throws IndexOutOfBoundsException, IOException;
/** /**
* Get the total number of bytes which will be read from the buffer * Get the total number of bytes which will be read from the buffer
@ -370,9 +372,10 @@ public abstract class Field implements Comparable<Field> {
* @param buf data buffer * @param buf data buffer
* @param offset data offset * @param offset data offset
* @return total number of bytes for this field stored within buf * @return total number of bytes for this field stored within buf
* @throws IndexOutOfBoundsException if invalid offset is specified
* @throws IOException thrown if IO error occurs * @throws IOException thrown if IO error occurs
*/ */
abstract int readLength(Buffer buf, int offset) throws IOException; abstract int readLength(Buffer buf, int offset) throws IndexOutOfBoundsException, IOException;
/** /**
* Get the number of bytes required to store this field value. * Get the number of bytes required to store this field value.
@ -445,8 +448,9 @@ public abstract class Field implements Comparable<Field> {
* @return comparison value, zero if equal, -1 if this field has a value * @return comparison value, zero if equal, -1 if this field has a value
* less than the stored field, or +1 if this field has a value greater than * less than the stored field, or +1 if this field has a value greater than
* the stored field located at keyIndex. * the stored field located at keyIndex.
* @throws IndexOutOfBoundsException if invalid offset is specified
*/ */
abstract int compareTo(DataBuffer buffer, int offset); abstract int compareTo(DataBuffer buffer, int offset) throws IndexOutOfBoundsException;
/** /**
* Compares this Field with another Field for order. Returns a * Compares this Field with another Field for order. Returns a
@ -515,8 +519,9 @@ public abstract class Field implements Comparable<Field> {
/** /**
* Get the type index value of the FixedField type which corresponds * Get the type index value of the FixedField type which corresponds
* to the specified fixed-length; * to the specified fixed-length;
* @param fixedLength fixed length * @param fixedLength fixed length (currently only 10 is supported)
* @return FixedLength field type index * @return FixedLength field type index
* @throws IllegalArgumentException if unsupported fixedLength is specified
*/ */
static byte getFixedType(int fixedLength) { static byte getFixedType(int fixedLength) {
if (fixedLength == 10) { if (fixedLength == 10) {

View file

@ -188,7 +188,7 @@ public class FixedField10 extends FixedField {
} }
@Override @Override
int write(Buffer buf, int offset) throws IOException { int write(Buffer buf, int offset) throws IndexOutOfBoundsException, IOException {
if (data != null) { if (data != null) {
return buf.put(offset, data); return buf.put(offset, data);
} }
@ -197,7 +197,7 @@ public class FixedField10 extends FixedField {
} }
@Override @Override
int read(Buffer buf, int offset) throws IOException { int read(Buffer buf, int offset) throws IndexOutOfBoundsException, IOException {
updatingValue(); updatingValue();
data = null; // be lazy data = null; // be lazy
hi8 = buf.getLong(offset); hi8 = buf.getLong(offset);
@ -206,7 +206,7 @@ public class FixedField10 extends FixedField {
} }
@Override @Override
int readLength(Buffer buf, int offset) throws IOException { int readLength(Buffer buf, int offset) {
return 10; return 10;
} }

View file

@ -108,19 +108,19 @@ class IndexField extends Field {
} }
@Override @Override
int write(Buffer buf, int offset) throws IOException { int write(Buffer buf, int offset) throws IndexOutOfBoundsException, IOException {
offset = indexedField.write(buf, offset); offset = indexedField.write(buf, offset);
return primaryKey.write(buf, offset); return primaryKey.write(buf, offset);
} }
@Override @Override
int read(Buffer buf, int offset) throws IOException { int read(Buffer buf, int offset) throws IndexOutOfBoundsException, IOException {
offset = indexedField.read(buf, offset); offset = indexedField.read(buf, offset);
return primaryKey.read(buf, offset); return primaryKey.read(buf, offset);
} }
@Override @Override
int readLength(Buffer buf, int offset) throws IOException { int readLength(Buffer buf, int offset) throws IndexOutOfBoundsException, IOException {
return indexedField.readLength(buf, offset) + primaryKey.length(); return indexedField.readLength(buf, offset) + primaryKey.length();
} }
@ -229,7 +229,7 @@ class IndexField extends Field {
} }
@Override @Override
int compareTo(DataBuffer buffer, int offset) { int compareTo(DataBuffer buffer, int offset) throws IndexOutOfBoundsException {
int result = indexedField.compareTo(buffer, offset); int result = indexedField.compareTo(buffer, offset);
if (result != 0) { if (result != 0) {
return result; return result;

View file

@ -94,19 +94,19 @@ public final class IntField extends PrimitiveField {
} }
@Override @Override
int write(Buffer buf, int offset) throws IOException { int write(Buffer buf, int offset) throws IndexOutOfBoundsException, IOException {
return buf.putInt(offset, value); return buf.putInt(offset, value);
} }
@Override @Override
int read(Buffer buf, int offset) throws IOException { int read(Buffer buf, int offset) throws IndexOutOfBoundsException, IOException {
updatingPrimitiveValue(); updatingPrimitiveValue();
value = buf.getInt(offset); value = buf.getInt(offset);
return offset + 4; return offset + 4;
} }
@Override @Override
int readLength(Buffer buf, int offset) throws IOException { int readLength(Buffer buf, int offset) {
return 4; return 4;
} }

View file

@ -94,19 +94,19 @@ public final class LongField extends PrimitiveField {
} }
@Override @Override
int write(Buffer buf, int offset) throws IOException { int write(Buffer buf, int offset) throws IndexOutOfBoundsException, IOException {
return buf.putLong(offset, value); return buf.putLong(offset, value);
} }
@Override @Override
int read(Buffer buf, int offset) throws IOException { int read(Buffer buf, int offset) throws IndexOutOfBoundsException, IOException {
updatingPrimitiveValue(); updatingPrimitiveValue();
value = buf.getLong(offset); value = buf.getLong(offset);
return offset + 8; return offset + 8;
} }
@Override @Override
int readLength(Buffer buf, int offset) throws IOException { int readLength(Buffer buf, int offset) {
return 8; return 8;
} }

View file

@ -51,7 +51,7 @@ class MasterTable {
try { try {
masterRecord.setRootBufferId(dbParms.get(DBParms.MASTER_TABLE_ROOT_BUFFER_ID_PARM)); masterRecord.setRootBufferId(dbParms.get(DBParms.MASTER_TABLE_ROOT_BUFFER_ID_PARM));
} }
catch (ArrayIndexOutOfBoundsException e) { catch (IndexOutOfBoundsException e) {
throw new IOException("Corrupt database parameters", e); throw new IOException("Corrupt database parameters", e);
} }
@ -157,7 +157,7 @@ class MasterTable {
table.tableRecordChanged(); table.tableRecordChanged();
} }
} }
catch (ArrayIndexOutOfBoundsException e) { catch (IndexOutOfBoundsException e) {
throw new IOException("Corrupt database parameters", e); throw new IOException("Corrupt database parameters", e);
} }

View file

@ -325,7 +325,7 @@ public class Schema {
initializeSparseColumnSet(sparseColumns); initializeSparseColumnSet(sparseColumns);
return consumed; return consumed;
} }
catch (ArrayIndexOutOfBoundsException e) { catch (IndexOutOfBoundsException e) {
throw new UnsupportedFieldException("Incomplete sparse column data"); throw new UnsupportedFieldException("Incomplete sparse column data");
} }
} }

View file

@ -94,12 +94,12 @@ public final class ShortField extends PrimitiveField {
} }
@Override @Override
int write(Buffer buf, int offset) throws IOException { int write(Buffer buf, int offset) throws IndexOutOfBoundsException, IOException {
return buf.putShort(offset, value); return buf.putShort(offset, value);
} }
@Override @Override
int read(Buffer buf, int offset) throws IOException { int read(Buffer buf, int offset) throws IndexOutOfBoundsException, IOException {
updatingPrimitiveValue(); updatingPrimitiveValue();
value = buf.getShort(offset); value = buf.getShort(offset);
return offset + 2; return offset + 2;

View file

@ -45,7 +45,7 @@ public class SparseRecord extends DBRecord {
} }
@Override @Override
public void write(Buffer buf, int offset) throws IOException { public void write(Buffer buf, int offset) throws IndexOutOfBoundsException, IOException {
ArrayList<Integer> sparseFieldIndexes = new ArrayList<>(); ArrayList<Integer> sparseFieldIndexes = new ArrayList<>();
Field[] fields = getFields(); Field[] fields = getFields();
for (int i = 0; i < fields.length; i++) { for (int i = 0; i < fields.length; i++) {
@ -74,7 +74,7 @@ public class SparseRecord extends DBRecord {
} }
@Override @Override
public void read(Buffer buf, int offset) throws IOException { public void read(Buffer buf, int offset) throws IndexOutOfBoundsException, IOException {
Field[] fields = getFields(); Field[] fields = getFields();
for (int i = 0; i < fields.length; i++) { for (int i = 0; i < fields.length; i++) {
Field f = fields[i]; Field f = fields[i];

View file

@ -105,7 +105,7 @@ public final class StringField extends Field {
} }
@Override @Override
int write(Buffer buf, int offset) throws IOException { int write(Buffer buf, int offset) throws IndexOutOfBoundsException, IOException {
if (bytes == null) { if (bytes == null) {
return buf.putInt(offset, -1); return buf.putInt(offset, -1);
} }
@ -114,7 +114,7 @@ public final class StringField extends Field {
} }
@Override @Override
int read(Buffer buf, int offset) throws IOException { int read(Buffer buf, int offset) throws IndexOutOfBoundsException, IOException {
checkImmutable(); checkImmutable();
int len = buf.getInt(offset); int len = buf.getInt(offset);
offset += 4; offset += 4;
@ -131,7 +131,7 @@ public final class StringField extends Field {
} }
@Override @Override
int readLength(Buffer buf, int offset) throws IOException { int readLength(Buffer buf, int offset) throws IndexOutOfBoundsException, IOException {
int len = buf.getInt(offset); int len = buf.getInt(offset);
return (len < 0 ? 0 : len) + 4; return (len < 0 ? 0 : len) + 4;
} }
@ -217,7 +217,7 @@ public final class StringField extends Field {
} }
@Override @Override
int compareTo(DataBuffer buffer, int offset) { int compareTo(DataBuffer buffer, int offset) throws IndexOutOfBoundsException {
StringField f = new StringField(); StringField f = new StringField();
try { try {
f.read(buffer, offset); f.read(buffer, offset);

View file

@ -150,7 +150,7 @@ public class DataBuffer implements Buffer, Externalizable {
@Override @Override
public void get(int offset, byte[] bytes, int dataOffset, int length) public void get(int offset, byte[] bytes, int dataOffset, int length)
throws ArrayIndexOutOfBoundsException { throws IndexOutOfBoundsException {
System.arraycopy(data, offset, bytes, dataOffset, length); System.arraycopy(data, offset, bytes, dataOffset, length);
} }
@ -160,7 +160,7 @@ public class DataBuffer implements Buffer, Externalizable {
} }
@Override @Override
public byte[] get(int offset, int length) throws ArrayIndexOutOfBoundsException { public byte[] get(int offset, int length) throws IndexOutOfBoundsException {
byte[] bytes = new byte[length]; byte[] bytes = new byte[length];
System.arraycopy(data, offset, bytes, 0, bytes.length); System.arraycopy(data, offset, bytes, 0, bytes.length);
return bytes; return bytes;
@ -255,7 +255,7 @@ public class DataBuffer implements Buffer, Externalizable {
* @param src source offset within this buffer * @param src source offset within this buffer
* @param dest destination offset within this buffer * @param dest destination offset within this buffer
* @param length length of data to be moved * @param length length of data to be moved
* @throws ArrayIndexOutOfBoundsException is thrown if parameters result in * @throws IndexOutOfBoundsException is thrown if parameters result in
* data access beyond the buffer size. * data access beyond the buffer size.
*/ */
public void move(int src, int dest, int length) { public void move(int src, int dest, int length) {
@ -269,7 +269,7 @@ public class DataBuffer implements Buffer, Externalizable {
* @param buf source buffer * @param buf source buffer
* @param bufOffset source buffer offset * @param bufOffset source buffer offset
* @param length amount of data to copy. * @param length amount of data to copy.
* @throws ArrayIndexOutOfBoundsException is thrown if parameters result in * @throws IndexOutOfBoundsException is thrown if parameters result in
* data access beyond the buffer size. * data access beyond the buffer size.
*/ */
public void copy(int offset, DataBuffer buf, int bufOffset, int length) { public void copy(int offset, DataBuffer buf, int bufOffset, int length) {
@ -386,7 +386,7 @@ public class DataBuffer implements Buffer, Externalizable {
* @param offset offset within this buffer * @param offset offset within this buffer
* @param len length of data within this buffer * @param len length of data within this buffer
* @return unsigned comparison result * @return unsigned comparison result
* @throws ArrayIndexOutOfBoundsException if specified region is not * @throws IndexOutOfBoundsException if specified region is not
* contained within this buffer. * contained within this buffer.
*/ */
public int unsignedCompareTo(byte[] otherData, int offset, int len) { public int unsignedCompareTo(byte[] otherData, int offset, int len) {

View file

@ -153,7 +153,7 @@ public abstract class AbstractChainedBufferTest extends AbstractGenericTest {
try { try {
cb.fill(0, 1, (byte) 0x12); cb.fill(0, 1, (byte) 0x12);
} }
catch (ArrayIndexOutOfBoundsException e) { catch (IndexOutOfBoundsException e) {
return; return;
} }
@ -241,7 +241,7 @@ public abstract class AbstractChainedBufferTest extends AbstractGenericTest {
cb.put(-1, bytes2); cb.put(-1, bytes2);
Assert.fail(); Assert.fail();
} }
catch (ArrayIndexOutOfBoundsException e) { catch (IndexOutOfBoundsException e) {
// good // good
} }
@ -249,7 +249,7 @@ public abstract class AbstractChainedBufferTest extends AbstractGenericTest {
cb.put(size - 1, bytes2); cb.put(size - 1, bytes2);
Assert.fail(); Assert.fail();
} }
catch (ArrayIndexOutOfBoundsException e) { catch (IndexOutOfBoundsException e) {
// good // good
} }
@ -257,7 +257,7 @@ public abstract class AbstractChainedBufferTest extends AbstractGenericTest {
cb.put(size + 1, bytes2); cb.put(size + 1, bytes2);
Assert.fail(); Assert.fail();
} }
catch (ArrayIndexOutOfBoundsException e) { catch (IndexOutOfBoundsException e) {
// good // good
} }
@ -265,7 +265,7 @@ public abstract class AbstractChainedBufferTest extends AbstractGenericTest {
cb.get(-1, bytes2); cb.get(-1, bytes2);
Assert.fail(); Assert.fail();
} }
catch (ArrayIndexOutOfBoundsException e) { catch (IndexOutOfBoundsException e) {
// good // good
} }
@ -273,7 +273,7 @@ public abstract class AbstractChainedBufferTest extends AbstractGenericTest {
cb.get(size - 1, bytes2); cb.get(size - 1, bytes2);
Assert.fail(); Assert.fail();
} }
catch (ArrayIndexOutOfBoundsException e) { catch (IndexOutOfBoundsException e) {
// good // good
} }
@ -281,7 +281,7 @@ public abstract class AbstractChainedBufferTest extends AbstractGenericTest {
cb.get(size + 1, bytes2); cb.get(size + 1, bytes2);
Assert.fail(); Assert.fail();
} }
catch (ArrayIndexOutOfBoundsException e) { catch (IndexOutOfBoundsException e) {
// good // good
} }
} }
@ -313,7 +313,7 @@ public abstract class AbstractChainedBufferTest extends AbstractGenericTest {
cb.putByte(-1, (byte) 0); cb.putByte(-1, (byte) 0);
Assert.fail(); Assert.fail();
} }
catch (ArrayIndexOutOfBoundsException e) { catch (IndexOutOfBoundsException e) {
// good // good
} }
@ -321,7 +321,7 @@ public abstract class AbstractChainedBufferTest extends AbstractGenericTest {
cb.putByte(size + 1, (byte) 0); cb.putByte(size + 1, (byte) 0);
Assert.fail(); Assert.fail();
} }
catch (ArrayIndexOutOfBoundsException e) { catch (IndexOutOfBoundsException e) {
// good // good
} }
} }
@ -361,7 +361,7 @@ public abstract class AbstractChainedBufferTest extends AbstractGenericTest {
cb.getByte(-1); cb.getByte(-1);
Assert.fail(); Assert.fail();
} }
catch (ArrayIndexOutOfBoundsException e) { catch (IndexOutOfBoundsException e) {
// good // good
} }
@ -369,7 +369,7 @@ public abstract class AbstractChainedBufferTest extends AbstractGenericTest {
cb.getByte(size + 1); cb.getByte(size + 1);
Assert.fail(); Assert.fail();
} }
catch (ArrayIndexOutOfBoundsException e) { catch (IndexOutOfBoundsException e) {
// good // good
} }
} }
@ -418,7 +418,7 @@ public abstract class AbstractChainedBufferTest extends AbstractGenericTest {
cb.putInt(-1, 0); cb.putInt(-1, 0);
Assert.fail(); Assert.fail();
} }
catch (ArrayIndexOutOfBoundsException e) { catch (IndexOutOfBoundsException e) {
// good // good
} }
@ -426,7 +426,7 @@ public abstract class AbstractChainedBufferTest extends AbstractGenericTest {
cb.putInt(size - 1, 0); cb.putInt(size - 1, 0);
Assert.fail(); Assert.fail();
} }
catch (ArrayIndexOutOfBoundsException e) { catch (IndexOutOfBoundsException e) {
// good // good
} }
@ -434,7 +434,7 @@ public abstract class AbstractChainedBufferTest extends AbstractGenericTest {
cb.putInt(size + 1, 0); cb.putInt(size + 1, 0);
Assert.fail(); Assert.fail();
} }
catch (ArrayIndexOutOfBoundsException e) { catch (IndexOutOfBoundsException e) {
// good // good
} }
} }
@ -482,7 +482,7 @@ public abstract class AbstractChainedBufferTest extends AbstractGenericTest {
cb.getInt(-1); cb.getInt(-1);
Assert.fail(); Assert.fail();
} }
catch (ArrayIndexOutOfBoundsException e) { catch (IndexOutOfBoundsException e) {
// good // good
} }
@ -490,7 +490,7 @@ public abstract class AbstractChainedBufferTest extends AbstractGenericTest {
cb.getInt(size - 1); cb.getInt(size - 1);
Assert.fail(); Assert.fail();
} }
catch (ArrayIndexOutOfBoundsException e) { catch (IndexOutOfBoundsException e) {
// good // good
} }
@ -498,7 +498,7 @@ public abstract class AbstractChainedBufferTest extends AbstractGenericTest {
cb.getInt(size + 1); cb.getInt(size + 1);
Assert.fail(); Assert.fail();
} }
catch (ArrayIndexOutOfBoundsException e) { catch (IndexOutOfBoundsException e) {
// good // good
} }
} }
@ -559,7 +559,7 @@ public abstract class AbstractChainedBufferTest extends AbstractGenericTest {
cb.putLong(-1, 0); cb.putLong(-1, 0);
Assert.fail(); Assert.fail();
} }
catch (ArrayIndexOutOfBoundsException e) { catch (IndexOutOfBoundsException e) {
// good // good
} }
@ -567,7 +567,7 @@ public abstract class AbstractChainedBufferTest extends AbstractGenericTest {
cb.putLong(size - 1, 0); cb.putLong(size - 1, 0);
Assert.fail(); Assert.fail();
} }
catch (ArrayIndexOutOfBoundsException e) { catch (IndexOutOfBoundsException e) {
// good // good
} }
@ -575,7 +575,7 @@ public abstract class AbstractChainedBufferTest extends AbstractGenericTest {
cb.putLong(size + 1, 0); cb.putLong(size + 1, 0);
Assert.fail(); Assert.fail();
} }
catch (ArrayIndexOutOfBoundsException e) { catch (IndexOutOfBoundsException e) {
// good // good
} }
} }
@ -635,7 +635,7 @@ public abstract class AbstractChainedBufferTest extends AbstractGenericTest {
cb.getLong(-1); cb.getLong(-1);
Assert.fail(); Assert.fail();
} }
catch (ArrayIndexOutOfBoundsException e) { catch (IndexOutOfBoundsException e) {
// good // good
} }
@ -643,7 +643,7 @@ public abstract class AbstractChainedBufferTest extends AbstractGenericTest {
cb.getLong(size - 1); cb.getLong(size - 1);
Assert.fail(); Assert.fail();
} }
catch (ArrayIndexOutOfBoundsException e) { catch (IndexOutOfBoundsException e) {
// good // good
} }
@ -651,7 +651,7 @@ public abstract class AbstractChainedBufferTest extends AbstractGenericTest {
cb.getLong(size + 1); cb.getLong(size + 1);
Assert.fail(); Assert.fail();
} }
catch (ArrayIndexOutOfBoundsException e) { catch (IndexOutOfBoundsException e) {
// good // good
} }
} }
@ -694,7 +694,7 @@ public abstract class AbstractChainedBufferTest extends AbstractGenericTest {
cb.putShort(-1, (short) 0); cb.putShort(-1, (short) 0);
Assert.fail(); Assert.fail();
} }
catch (ArrayIndexOutOfBoundsException e) { catch (IndexOutOfBoundsException e) {
// good // good
} }
@ -702,7 +702,7 @@ public abstract class AbstractChainedBufferTest extends AbstractGenericTest {
cb.putShort(size - 1, (short) 0); cb.putShort(size - 1, (short) 0);
Assert.fail(); Assert.fail();
} }
catch (ArrayIndexOutOfBoundsException e) { catch (IndexOutOfBoundsException e) {
// good // good
} }
@ -710,7 +710,7 @@ public abstract class AbstractChainedBufferTest extends AbstractGenericTest {
cb.putShort(size + 1, (short) 0); cb.putShort(size + 1, (short) 0);
Assert.fail(); Assert.fail();
} }
catch (ArrayIndexOutOfBoundsException e) { catch (IndexOutOfBoundsException e) {
// good // good
} }
} }
@ -752,7 +752,7 @@ public abstract class AbstractChainedBufferTest extends AbstractGenericTest {
cb.getShort(-1); cb.getShort(-1);
Assert.fail(); Assert.fail();
} }
catch (ArrayIndexOutOfBoundsException e) { catch (IndexOutOfBoundsException e) {
// good // good
} }
@ -760,7 +760,7 @@ public abstract class AbstractChainedBufferTest extends AbstractGenericTest {
cb.getShort(size - 1); cb.getShort(size - 1);
Assert.fail(); Assert.fail();
} }
catch (ArrayIndexOutOfBoundsException e) { catch (IndexOutOfBoundsException e) {
// good // good
} }
@ -768,7 +768,7 @@ public abstract class AbstractChainedBufferTest extends AbstractGenericTest {
cb.getShort(size + 1); cb.getShort(size + 1);
Assert.fail(); Assert.fail();
} }
catch (ArrayIndexOutOfBoundsException e) { catch (IndexOutOfBoundsException e) {
// good // good
} }
} }

View file

@ -23,6 +23,7 @@ import java.util.Arrays;
import org.junit.*; import org.junit.*;
import generic.test.AbstractGenericTest; import generic.test.AbstractGenericTest;
import ghidra.util.exception.ClosedException;
public class DBBufferTest extends AbstractGenericTest { public class DBBufferTest extends AbstractGenericTest {
@ -109,6 +110,32 @@ public class DBBufferTest extends AbstractGenericTest {
buf.get(0, data); buf.get(0, data);
assertTrue("Expected bytes in buffer", Arrays.equals(bytes, data)); assertTrue("Expected bytes in buffer", Arrays.equals(bytes, data));
dbh.close();
try {
txId = dbh.startTransaction();
fail("Expected closed exception");
}
catch (IllegalStateException e) {
// ignore
}
try {
dbh.getBuffer(bufId);
fail("Expected closed exception");
}
catch (ClosedException e) {
// ignore
}
try {
buf.get(0, data);
fail("Expected closed exception");
}
catch (ClosedException e) {
// ignore
}
} }
@Test @Test
@ -159,6 +186,6 @@ public class DBBufferTest extends AbstractGenericTest {
dbh.undo(); dbh.undo();
buf = dbh.getBuffer(bufId); buf = dbh.getBuffer(bufId);
assertEquals("Expected valid buffer", 0, buf.getByte(0)); assertEquals("Expected valid buffer", 0, buf.getByte(0));
} }
} }

View file

@ -40,13 +40,14 @@ class BufferSubMemoryBlock extends SubMemoryBlock {
} }
@Override @Override
public byte getByte(long offsetInMemBlock) throws IOException { public byte getByte(long offsetInMemBlock) throws IndexOutOfBoundsException, IOException {
long offsetInSubBlock = offsetInMemBlock - subBlockOffset; long offsetInSubBlock = offsetInMemBlock - subBlockOffset;
return buf.getByte((int) offsetInSubBlock); return buf.getByte((int) offsetInSubBlock);
} }
@Override @Override
public int getBytes(long offsetInMemBlock, byte[] b, int off, int len) throws IOException { public int getBytes(long offsetInMemBlock, byte[] b, int off, int len)
throws IndexOutOfBoundsException, IOException {
long offsetInSubBlock = offsetInMemBlock - subBlockOffset; long offsetInSubBlock = offsetInMemBlock - subBlockOffset;
long available = subBlockLength - offsetInSubBlock; long available = subBlockLength - offsetInSubBlock;
len = (int) Math.min(len, available); len = (int) Math.min(len, available);
@ -55,13 +56,15 @@ class BufferSubMemoryBlock extends SubMemoryBlock {
} }
@Override @Override
public void putByte(long offsetInMemBlock, byte b) throws IOException { public void putByte(long offsetInMemBlock, byte b)
throws IndexOutOfBoundsException, IOException {
long offsetInSubBlock = offsetInMemBlock - subBlockOffset; long offsetInSubBlock = offsetInMemBlock - subBlockOffset;
buf.putByte((int) offsetInSubBlock, b); buf.putByte((int) offsetInSubBlock, b);
} }
@Override @Override
public int putBytes(long offsetInMemBlock, byte[] b, int off, int len) throws IOException { public int putBytes(long offsetInMemBlock, byte[] b, int off, int len)
throws IndexOutOfBoundsException, IOException {
long offsetInSubBlock = offsetInMemBlock - subBlockOffset; long offsetInSubBlock = offsetInMemBlock - subBlockOffset;
long available = subBlockLength - offsetInSubBlock; long available = subBlockLength - offsetInSubBlock;
len = (int) Math.min(len, available); len = (int) Math.min(len, available);
@ -95,7 +98,8 @@ class BufferSubMemoryBlock extends SubMemoryBlock {
} }
@Override @Override
protected SubMemoryBlock split(long memBlockOffset) throws IOException { protected SubMemoryBlock split(long memBlockOffset)
throws IndexOutOfBoundsException, IOException {
// convert from offset in block to offset in this sub block // convert from offset in block to offset in this sub block
int offset = (int) (memBlockOffset - subBlockOffset); int offset = (int) (memBlockOffset - subBlockOffset);
long newLength = subBlockLength - offset; long newLength = subBlockLength - offset;

View file

@ -208,9 +208,10 @@ public class FileBytes {
* *
* @param offset the offset into the file bytes. * @param offset the offset into the file bytes.
* @param b the new byte value; * @param b the new byte value;
* @throws IndexOutOfBoundsException if invalid offset is specified
* @throws IOException if the write to the database fails. * @throws IOException if the write to the database fails.
*/ */
synchronized void putByte(long offset, byte b) throws IOException { synchronized void putByte(long offset, byte b) throws IndexOutOfBoundsException, IOException {
checkValid(); checkValid();
@ -252,6 +253,7 @@ public class FileBytes {
* @param off the offset into the byte array to get the bytes to write. * @param off the offset into the byte array to get the bytes to write.
* @param length the number of bytes to write. * @param length the number of bytes to write.
* @return the number of bytes written * @return the number of bytes written
* @throws IndexOutOfBoundsException if invalid offset is specified
* @throws IOException if the write to the database fails. * @throws IOException if the write to the database fails.
*/ */
synchronized int putBytes(long offset, byte[] b, int off, int length) throws IOException { synchronized int putBytes(long offset, byte[] b, int off, int length) throws IOException {
@ -294,7 +296,8 @@ public class FileBytes {
return length; return length;
} }
private byte getByte(DBBuffer[] buffers, long offset) throws IOException { private byte getByte(DBBuffer[] buffers, long offset)
throws IndexOutOfBoundsException, IOException {
checkValid(); checkValid();
@ -313,7 +316,7 @@ public class FileBytes {
} }
private int getBytes(DBBuffer[] buffers, long offset, byte[] b, int off, int length) private int getBytes(DBBuffer[] buffers, long offset, byte[] b, int off, int length)
throws IOException { throws IndexOutOfBoundsException, IOException {
checkValid(); checkValid();

View file

@ -344,7 +344,8 @@ public class MemoryBlockDB implements MemoryBlock {
} }
@Override @Override
public int getBytes(Address addr, byte[] b, int off, int len) throws MemoryAccessException { public int getBytes(Address addr, byte[] b, int off, int len)
throws IndexOutOfBoundsException, MemoryAccessException {
if (memMap.getLiveMemoryHandler() != null) { if (memMap.getLiveMemoryHandler() != null) {
return memMap.getBytes(addr, b, off, len); return memMap.getBytes(addr, b, off, len);
} }
@ -379,7 +380,8 @@ public class MemoryBlockDB implements MemoryBlock {
} }
@Override @Override
public int putBytes(Address addr, byte[] b, int off, int len) throws MemoryAccessException { public int putBytes(Address addr, byte[] b, int off, int len)
throws IndexOutOfBoundsException, MemoryAccessException {
if (memMap.getLiveMemoryHandler() != null) { if (memMap.getLiveMemoryHandler() != null) {
memMap.setBytes(addr, b, off, len); memMap.setBytes(addr, b, off, len);
return len; return len;
@ -460,12 +462,13 @@ public class MemoryBlockDB implements MemoryBlock {
return 0; return 0;
} }
public int getBytes(long offset, byte[] b, int off, int len) throws MemoryAccessException { public int getBytes(long offset, byte[] b, int off, int len)
throws IndexOutOfBoundsException, MemoryAccessException {
if (off < 0 || off + len > b.length) { if (off < 0 || off + len > b.length) {
throw new ArrayIndexOutOfBoundsException(); throw new IndexOutOfBoundsException();
} }
if (offset < 0 || offset >= length) { if (offset < 0 || offset >= length) {
throw new ArrayIndexOutOfBoundsException(); throw new IndexOutOfBoundsException();
} }
len = (int) Math.min(len, length - offset); len = (int) Math.min(len, length - offset);
@ -512,12 +515,13 @@ public class MemoryBlockDB implements MemoryBlock {
} }
} }
private int putBytes(long offset, byte[] b, int off, int len) throws MemoryAccessException { private int putBytes(long offset, byte[] b, int off, int len)
throws IndexOutOfBoundsException, MemoryAccessException {
if (off < 0 || off + len > b.length) { if (off < 0 || off + len > b.length) {
throw new ArrayIndexOutOfBoundsException(); throw new IndexOutOfBoundsException();
} }
if (offset < 0 || offset >= length) { if (offset < 0 || offset >= length) {
throw new ArrayIndexOutOfBoundsException(); throw new IndexOutOfBoundsException();
} }
len = (int) Math.min(len, length - offset); len = (int) Math.min(len, length - offset);

View file

@ -102,7 +102,7 @@ class MemoryBlockInputStream extends InputStream {
} }
@Override @Override
public int read(byte[] b, int off, int len) throws IOException { public int read(byte[] b, int off, int len) throws IndexOutOfBoundsException, IOException {
if (index >= numBytes) { if (index >= numBytes) {
return -1; return -1;
} }

View file

@ -89,10 +89,12 @@ abstract class SubMemoryBlock implements Comparable<SubMemoryBlock> {
* *
* @param memBlockOffset the offset from the start of the containing {@link MemoryBlockDB} * @param memBlockOffset the offset from the start of the containing {@link MemoryBlockDB}
* @return the byte at the given containing block offset. * @return the byte at the given containing block offset.
* @throws IndexOutOfBoundsException if invalid offset is specified
* @throws MemoryAccessException if the block is uninitialized. * @throws MemoryAccessException if the block is uninitialized.
* @throws IOException if there is a problem reading from the database * @throws IOException if there is a problem reading from the database
*/ */
public abstract byte getByte(long memBlockOffset) throws MemoryAccessException, IOException; public abstract byte getByte(long memBlockOffset)
throws IndexOutOfBoundsException, MemoryAccessException, IOException;
/** /**
* Tries to get len bytes from this block at the given offset (relative to the containing * Tries to get len bytes from this block at the given offset (relative to the containing
@ -103,13 +105,14 @@ abstract class SubMemoryBlock implements Comparable<SubMemoryBlock> {
* @param off the offset into the byte array. * @param off the offset into the byte array.
* @param len the number of bytes to get. * @param len the number of bytes to get.
* @return the number of bytes actually populated. * @return the number of bytes actually populated.
* @throws IndexOutOfBoundsException if invalid offset is specified
* @throws MemoryAccessException if any of the requested bytes are * @throws MemoryAccessException if any of the requested bytes are
* uninitialized. * uninitialized.
* @throws IOException if there is a problem reading from the database * @throws IOException if there is a problem reading from the database
* @throws IllegalArgumentException if the offset is not in this block. * @throws IllegalArgumentException if the offset is not in this block.
*/ */
public abstract int getBytes(long memBlockOffset, byte[] b, int off, int len) public abstract int getBytes(long memBlockOffset, byte[] b, int off, int len)
throws MemoryAccessException, IOException; throws IndexOutOfBoundsException, MemoryAccessException, IOException;
/** /**
* Stores the byte in this sub block at the given offset relative to the containing * Stores the byte in this sub block at the given offset relative to the containing
@ -118,12 +121,13 @@ abstract class SubMemoryBlock implements Comparable<SubMemoryBlock> {
* *
* @param memBlockOffset the offset from the start of the containing {@link MemoryBlockDB} * @param memBlockOffset the offset from the start of the containing {@link MemoryBlockDB}
* @param b the byte value to store at the given offset. * @param b the byte value to store at the given offset.
* @throws IndexOutOfBoundsException if invalid offset is specified
* @throws MemoryAccessException if the block is uninitialized * @throws MemoryAccessException if the block is uninitialized
* @throws IOException if there is a problem writing to the database * @throws IOException if there is a problem writing to the database
* @throws IllegalArgumentException if the offset is not in this block. * @throws IllegalArgumentException if the offset is not in this block.
*/ */
public abstract void putByte(long memBlockOffset, byte b) public abstract void putByte(long memBlockOffset, byte b)
throws MemoryAccessException, IOException; throws IndexOutOfBoundsException, MemoryAccessException, IOException;
/** /**
* Tries to write len bytes to this block at the given offset (relative to the containing * Tries to write len bytes to this block at the given offset (relative to the containing
@ -136,12 +140,13 @@ abstract class SubMemoryBlock implements Comparable<SubMemoryBlock> {
* @param off the offset into the byte array. * @param off the offset into the byte array.
* @param len the number of bytes to write. * @param len the number of bytes to write.
* @return the number of bytes actually written * @return the number of bytes actually written
* @throws IndexOutOfBoundsException if invalid offset is specified
* @throws MemoryAccessException if this block is uninitialized. * @throws MemoryAccessException if this block is uninitialized.
* @throws IOException if there is a problem writing to the database * @throws IOException if there is a problem writing to the database
* @throws IllegalArgumentException if the offset is not in this block. * @throws IllegalArgumentException if the offset is not in this block.
*/ */
public abstract int putBytes(long memBlockOffset, byte[] b, int off, int len) public abstract int putBytes(long memBlockOffset, byte[] b, int off, int len)
throws MemoryAccessException, IOException; throws IndexOutOfBoundsException, MemoryAccessException, IOException;
/** /**
* Deletes this SumMemoryBlock * Deletes this SumMemoryBlock
@ -204,9 +209,11 @@ abstract class SubMemoryBlock implements Comparable<SubMemoryBlock> {
* To get the offset relative to this SubMemoryBlock, you have to subtract this sub blocks * To get the offset relative to this SubMemoryBlock, you have to subtract this sub blocks
* starting offset. * starting offset.
* @return the new SubMemoryBlock that contains the back half of this block * @return the new SubMemoryBlock that contains the back half of this block
* @throws IndexOutOfBoundsException if invalid offset is specified
* @throws IOException if a database error occurs. * @throws IOException if a database error occurs.
*/ */
protected abstract SubMemoryBlock split(long memBlockOffset) throws IOException; protected abstract SubMemoryBlock split(long memBlockOffset)
throws IndexOutOfBoundsException, IOException;
/** /**
* Updates this SubMemoryBlock to have a new owning MemoryBlock and offset within that block. * Updates this SubMemoryBlock to have a new owning MemoryBlock and offset within that block.

View file

@ -476,6 +476,7 @@ public interface Memory extends AddressSetView {
* @param size the number of bytes to get. * @param size the number of bytes to get.
* @return the number of bytes put into dest. May be less than * @return the number of bytes put into dest. May be less than
* size if the requested number extends beyond initialized / available memory. * size if the requested number extends beyond initialized / available memory.
* @throws IndexOutOfBoundsException if an invalid index is specified
* @throws MemoryAccessException if the starting address is * @throws MemoryAccessException if the starting address is
* not contained in any memory block or is an uninitialized location. * not contained in any memory block or is an uninitialized location.
*/ */

View file

@ -231,10 +231,12 @@ public interface MemoryBlock extends Serializable, Comparable<MemoryBlock> {
* @param off the offset into the byte array. * @param off the offset into the byte array.
* @param len the number of bytes to get. * @param len the number of bytes to get.
* @return the number of bytes actually populated. * @return the number of bytes actually populated.
* @throws IndexOutOfBoundsException if invalid offset is specified
* @throws MemoryAccessException if any of the requested bytes are uninitialized. * @throws MemoryAccessException if any of the requested bytes are uninitialized.
* @throws IllegalArgumentException if the Address is not in this block. * @throws IllegalArgumentException if the Address is not in this block.
*/ */
public int getBytes(Address addr, byte[] b, int off, int len) throws MemoryAccessException; public int getBytes(Address addr, byte[] b, int off, int len)
throws IndexOutOfBoundsException, MemoryAccessException;
/** /**
* Puts the given byte at the given address in this block. * Puts the given byte at the given address in this block.
@ -266,18 +268,24 @@ public interface MemoryBlock extends Serializable, Comparable<MemoryBlock> {
* @param off the offset into the byte array. * @param off the offset into the byte array.
* @param len the number of bytes to write. * @param len the number of bytes to write.
* @return the number of bytes actually written. * @return the number of bytes actually written.
* @throws IndexOutOfBoundsException if invalid offset is specified
* @throws MemoryAccessException if the block is uninitialized * @throws MemoryAccessException if the block is uninitialized
* @throws IllegalArgumentException if the Address is not in this block. * @throws IllegalArgumentException if the Address is not in this block.
*/ */
public int putBytes(Address addr, byte[] b, int off, int len) throws MemoryAccessException; public int putBytes(Address addr, byte[] b, int off, int len)
throws IndexOutOfBoundsException, MemoryAccessException;
/** /**
* Get the type for this block: DEFAULT, BIT_MAPPED, or BYTE_MAPPED * Get the type for this block: DEFAULT, BIT_MAPPED, or BYTE_MAPPED
* (see {@link MemoryBlockType}).
* @return memory block type
*/ */
public MemoryBlockType getType(); public MemoryBlockType getType();
/** /**
* Return whether this block has been initialized. * Return whether this block has been initialized.
*
* @return true if block is fully initialized else false
*/ */
public boolean isInitialized(); public boolean isInitialized();