Commit 2a904ad6 authored by Andre Freyssinet's avatar Andre Freyssinet

Bug fix (JORAM-308): Patch to avoid NPE in Transaction with null string. A

better fix shoul be to use NullableString encoding but it will break the
data store compatibility.
parent 6c899d74
/*
* Copyright (C) 2013 ScalAgent Distributed Technologies
* Copyright (C) 2013 - 2018 ScalAgent Distributed Technologies
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
......@@ -35,6 +35,7 @@ public class EncodableHelper {
* @return the size of the encoded string
*/
public static final int getStringEncodedSize(String s) {
// TODO (AF): Prevents a NPE, encodes an empty string if null
return Encodable.INT_ENCODED_SIZE + s.length();
}
......
......@@ -860,8 +860,16 @@ public final class Message implements Cloneable, Serializable, Streamable, Encod
}
public int getEncodedSize() throws Exception {
if (id == null) { // TODO (AF): JORAM-308
logger.log(BasicLevel.WARN, "Message: Null id.");
id = "";
}
int encodedSize = EncodableHelper.getStringEncodedSize(id);
if (toId == null) { // TODO (AF): JORAM-308
logger.log(BasicLevel.WARN, "Message: Null toId.");
toId = "";
}
encodedSize += EncodableHelper.getStringEncodedSize(toId);
encodedSize += EncodableHelper.getNullableStringEncodedSize(toName);
encodedSize += BYTE_ENCODED_SIZE + LONG_ENCODED_SIZE + BOOLEAN_ENCODED_SIZE + LONG_ENCODED_SIZE + SHORT_ENCODED_SIZE;
......@@ -869,6 +877,8 @@ public final class Message implements Cloneable, Serializable, Streamable, Encod
if (type != org.objectweb.joram.shared.messages.Message.SIMPLE) { encodedSize += BYTE_ENCODED_SIZE; }
if (replyToId != null) {
encodedSize += EncodableHelper.getStringEncodedSize(replyToId);
// TODO (AF): Should be a NullableString (be careful to data store compatibility).
if (replyToName == null) replyToName = "";
encodedSize += EncodableHelper.getStringEncodedSize(replyToName);
encodedSize += BYTE_ENCODED_SIZE;
}
......@@ -882,8 +892,7 @@ public final class Message implements Cloneable, Serializable, Streamable, Encod
if (bodyLength < 0) {
encodedSize += EncodableHelper.getNullableByteArrayEncodedSize(body);
} else {
encodedSize += EncodableHelper.getNullableByteArrayEncodedSize(body,
bodyLength);
encodedSize += EncodableHelper.getNullableByteArrayEncodedSize(body, bodyLength);
}
encodedSize += EncodableHelper.getNullableStringEncodedSize(clientID);
......@@ -918,6 +927,7 @@ public final class Message implements Cloneable, Serializable, Streamable, Encod
if (type != org.objectweb.joram.shared.messages.Message.SIMPLE) { encoder.encodeByte((byte) type); }
if (replyToId != null) {
encoder.encodeString(replyToId);
// TODO (AF): Should be a NullableString (be careful to data store compatibility).
encoder.encodeString(replyToName);
encoder.encodeByte(replyToType);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment