activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chir...@apache.org
Subject [1/2] git commit: Fixing bug where the DataByteArrayInputStream was not throwing EOFExceptions when reads were going past the end of the byte array.
Date Wed, 04 Dec 2013 17:09:02 GMT
Updated Branches:
  refs/heads/trunk 69e35d6c4 -> 02ef9445d


Fixing bug where the DataByteArrayInputStream was not throwing EOFExceptions when reads were
going past the end of the byte array.

This would make it harder to figure out when things went wrong.


Project: http://git-wip-us.apache.org/repos/asf/activemq/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq/commit/02ef9445
Tree: http://git-wip-us.apache.org/repos/asf/activemq/tree/02ef9445
Diff: http://git-wip-us.apache.org/repos/asf/activemq/diff/02ef9445

Branch: refs/heads/trunk
Commit: 02ef9445dddcffc5f701dcb43ef0fa3d6acbc307
Parents: 8378cb1
Author: Hiram Chirino <hiram@hiramchirino.com>
Authored: Wed Dec 4 12:08:28 2013 -0500
Committer: Hiram Chirino <hiram@hiramchirino.com>
Committed: Wed Dec 4 12:09:47 2013 -0500

----------------------------------------------------------------------
 .../activemq/command/XATransactionId.java       |  4 +-
 .../activemq/util/DataByteArrayInputStream.java | 58 +++++++++++---------
 2 files changed, 35 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq/blob/02ef9445/activemq-client/src/main/java/org/apache/activemq/command/XATransactionId.java
----------------------------------------------------------------------
diff --git a/activemq-client/src/main/java/org/apache/activemq/command/XATransactionId.java
b/activemq-client/src/main/java/org/apache/activemq/command/XATransactionId.java
index e963c87..5f786e5 100755
--- a/activemq-client/src/main/java/org/apache/activemq/command/XATransactionId.java
+++ b/activemq-client/src/main/java/org/apache/activemq/command/XATransactionId.java
@@ -50,7 +50,7 @@ public class XATransactionId extends TransactionId implements Xid, Comparable
{
         this.branchQualifier = xid.getBranchQualifier();
     }
 
-    public XATransactionId(byte[] encodedBytes) {
+    public XATransactionId(byte[] encodedBytes) throws IOException {
         encodedXidBytes = encodedBytes;
         initFromEncodedBytes();
     }
@@ -61,7 +61,7 @@ public class XATransactionId extends TransactionId implements Xid, Comparable
{
 
     final int XID_PREFIX_SIZE = 16;
     //+|-,(long)lastAck,(byte)priority,(int)formatid,(short)globalLength....
-    private void initFromEncodedBytes() {
+    private void initFromEncodedBytes() throws IOException {
         DataByteArrayInputStream inputStream = new DataByteArrayInputStream(encodedXidBytes);
         inputStream.skipBytes(10);
         formatId = inputStream.readInt();

http://git-wip-us.apache.org/repos/asf/activemq/blob/02ef9445/activemq-client/src/main/java/org/apache/activemq/util/DataByteArrayInputStream.java
----------------------------------------------------------------------
diff --git a/activemq-client/src/main/java/org/apache/activemq/util/DataByteArrayInputStream.java
b/activemq-client/src/main/java/org/apache/activemq/util/DataByteArrayInputStream.java
index 9bf229d..0a13aa0 100755
--- a/activemq-client/src/main/java/org/apache/activemq/util/DataByteArrayInputStream.java
+++ b/activemq-client/src/main/java/org/apache/activemq/util/DataByteArrayInputStream.java
@@ -16,10 +16,7 @@
  */
 package org.apache.activemq.util;
 
-import java.io.DataInput;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.UTFDataFormatException;
+import java.io.*;
 
 /**
  * Optimized ByteArrayInputStream that can be used more than once
@@ -124,6 +121,14 @@ public final class DataByteArrayInputStream extends InputStream implements
DataI
         return (pos < buf.length) ? (buf[pos++] & 0xff) : -1;
     }
 
+    public int readOrIOException() throws IOException {
+        int rc = read();
+        if( rc == -1 ) {
+            throw new EOFException();
+        }
+        return rc;
+    }
+
     /**
      * Reads up to <code>len</code> bytes of data into an array of bytes from
      * this input stream.
@@ -180,45 +185,48 @@ public final class DataByteArrayInputStream extends InputStream implements
DataI
         return n;
     }
 
-    public boolean readBoolean() {
-        return read() != 0;
+    public boolean readBoolean() throws IOException {
+        return readOrIOException() != 0;
     }
 
-    public byte readByte() {
-        return (byte)read();
+    public byte readByte() throws IOException {
+        return (byte)readOrIOException();
     }
 
-    public int readUnsignedByte() {
-        return read();
+    public int readUnsignedByte() throws IOException {
+        return readOrIOException();
     }
 
-    public short readShort() {
-        int ch1 = read();
-        int ch2 = read();
+    public short readShort() throws IOException {
+        int ch1 = readOrIOException();
+        int ch2 = readOrIOException();
         return (short)((ch1 << 8) + (ch2 << 0));
     }
 
-    public int readUnsignedShort() {
-        int ch1 = read();
-        int ch2 = read();
+    public int readUnsignedShort() throws IOException {
+        int ch1 = readOrIOException();
+        int ch2 = readOrIOException();
         return (ch1 << 8) + (ch2 << 0);
     }
 
-    public char readChar() {
-        int ch1 = read();
-        int ch2 = read();
+    public char readChar() throws IOException {
+        int ch1 = readOrIOException();
+        int ch2 = readOrIOException();
         return (char)((ch1 << 8) + (ch2 << 0));
     }
 
-    public int readInt() {
-        int ch1 = read();
-        int ch2 = read();
-        int ch3 = read();
-        int ch4 = read();
+    public int readInt() throws IOException {
+        int ch1 = readOrIOException();
+        int ch2 = readOrIOException();
+        int ch3 = readOrIOException();
+        int ch4 = readOrIOException();
         return (ch1 << 24) + (ch2 << 16) + (ch3 << 8) + (ch4 << 0);
     }
 
-    public long readLong() {
+    public long readLong() throws IOException {
+        if (pos >= buf.length ) {
+            throw new EOFException();
+        }
         long rc = ((long)buf[pos++] << 56) + ((long)(buf[pos++] & 255) <<
48) + ((long)(buf[pos++] & 255) << 40) + ((long)(buf[pos++] & 255) <<
32);
         return rc + ((long)(buf[pos++] & 255) << 24) + ((buf[pos++] & 255)
<< 16) + ((buf[pos++] & 255) << 8) + ((buf[pos++] & 255) << 0);
     }


Mime
View raw message