From 41bef7c0b619c7bc925326451a56071b5736580a Mon Sep 17 00:00:00 2001
From: Matthew Swift <matthew.swift@forgerock.com>
Date: Wed, 19 Jun 2013 08:36:16 +0000
Subject: [PATCH] Fix OPENDJ-986: Exception when reading messages from Replication server RS
---
opends/src/server/org/opends/server/replication/protocol/UpdateMsg.java | 41 ++++++++++++++++++++++++-----------------
1 files changed, 24 insertions(+), 17 deletions(-)
diff --git a/opends/src/server/org/opends/server/replication/protocol/UpdateMsg.java b/opends/src/server/org/opends/server/replication/protocol/UpdateMsg.java
index 1c30cc8..cbef678 100644
--- a/opends/src/server/org/opends/server/replication/protocol/UpdateMsg.java
+++ b/opends/src/server/org/opends/server/replication/protocol/UpdateMsg.java
@@ -109,6 +109,8 @@
/**
* Creates a new UpdateMsg with the given informations.
+ * <p>
+ * This constructor is only used for testing.
*
* @param changeNumber The ChangeNumber associated with the change
* encoded in this message.
@@ -179,18 +181,6 @@
return changeNumber.compareTo(msg.getChangeNumber());
}
-
- /**
- * {@inheritDoc}
- */
- @Override
- public byte[] getBytes(short reqProtocolVersion)
- throws UnsupportedEncodingException
- {
- // There was no change since version 2.
- return getBytes();
- }
-
/**
* Get the assured mode in this message.
* @return The assured mode in this message
@@ -355,20 +345,37 @@
}
/**
+ * Returns the encoded representation of this update message using the current
+ * protocol version.
+ *
+ * @return The encoded representation of this update message.
+ * @throws UnsupportedEncodingException
+ * If the message could not be encoded.
+ */
+ public byte[] getBytes() throws UnsupportedEncodingException
+ {
+ return getBytes(ProtocolVersion.getCurrentVersion());
+ }
+
+ /**
+ * This implementation is only called during unit testing, so we are free to
+ * force the protocol version. Underlying implementations override this method
+ * in order to provide version specific encodings.
+ *
* {@inheritDoc}
*/
@Override
- public byte[] getBytes() throws UnsupportedEncodingException
+ public byte[] getBytes(short protocolVersion)
+ throws UnsupportedEncodingException
{
/* Encode the header in a byte[] large enough to also contain the payload */
- byte [] resultByteArray =
- encodeHeader(MSG_TYPE_GENERIC_UPDATE, payload.length,
- ProtocolVersion.getCurrentVersion());
+ byte[] resultByteArray = encodeHeader(MSG_TYPE_GENERIC_UPDATE,
+ payload.length, ProtocolVersion.getCurrentVersion());
int pos = resultByteArray.length - payload.length;
/* Add the payload */
- for (int i=0; i<payload.length; i++,pos++)
+ for (int i = 0; i < payload.length; i++, pos++)
{
resultByteArray[pos] = payload[i];
}
--
Gitblit v1.10.0