diff options
author | Tobias Holgers <tholgers@users.sourceforge.net> | 2009-06-30 17:27:55 +0000 |
---|---|---|
committer | Tobias Holgers <tholgers@users.sourceforge.net> | 2009-06-30 17:27:55 +0000 |
commit | ddad54db7b38b9b919ef59dc988c1b2194fa184c (patch) | |
tree | 4054184cfb9e81db21b0f4eca2b6673b7b4e134d | |
parent | be265775e90f926715d7a9f74963fa517f83a8bc (diff) |
Always clone single byte array properties as some implementations reuse the array for cursors (e.g. BDB-C 4.6).
3 files changed, 17 insertions, 9 deletions
diff --git a/src/main/java/com/amazon/carbonado/raw/DataDecoder.java b/src/main/java/com/amazon/carbonado/raw/DataDecoder.java index 407df0c..11fa4c7 100644 --- a/src/main/java/com/amazon/carbonado/raw/DataDecoder.java +++ b/src/main/java/com/amazon/carbonado/raw/DataDecoder.java @@ -648,7 +648,7 @@ public class DataDecoder { /**
* Decodes the given byte array which was encoded by {@link
- * DataEncoder#encodeSingle}.
+ * DataEncoder#encodeSingle}. Always returns a new byte array instance.
*
* @param prefixPadding amount of extra bytes to skip from start of encoded byte array
* @param suffixPadding amount of extra bytes to skip at end of encoded byte array
@@ -662,7 +662,8 @@ public class DataDecoder { return EMPTY_BYTE_ARRAY;
}
if (prefixPadding <= 0 && suffixPadding <= 0) {
- return src;
+ // Always return a new byte array instance
+ return src.clone();
}
byte[] dst = new byte[length];
System.arraycopy(src, prefixPadding, dst, 0, length);
@@ -674,7 +675,8 @@ public class DataDecoder { /**
* Decodes the given byte array which was encoded by {@link
- * DataEncoder#encodeSingleNullable}.
+ * DataEncoder#encodeSingleNullable}. Always returns a new byte array
+ * instance.
*/
public static byte[] decodeSingleNullable(byte[] src) throws CorruptEncodingException {
return decodeSingleNullable(src, 0, 0);
@@ -682,7 +684,8 @@ public class DataDecoder { /**
* Decodes the given byte array which was encoded by {@link
- * DataEncoder#encodeSingleNullable}.
+ * DataEncoder#encodeSingleNullable}. Always returns a new byte array
+ * instance.
*
* @param prefixPadding amount of extra bytes to skip from start of encoded byte array
* @param suffixPadding amount of extra bytes to skip at end of encoded byte array
diff --git a/src/main/java/com/amazon/carbonado/raw/GenericEncodingStrategy.java b/src/main/java/com/amazon/carbonado/raw/GenericEncodingStrategy.java index b7356d7..dcc8d45 100644 --- a/src/main/java/com/amazon/carbonado/raw/GenericEncodingStrategy.java +++ b/src/main/java/com/amazon/carbonado/raw/GenericEncodingStrategy.java @@ -1906,7 +1906,10 @@ public class GenericEncodingStrategy<S extends Storable> { a.invokeStatic(DataDecoder.class.getName(), "decodeSingle",
byteArrayType, params);
} else {
- // Just store raw property value.
+ // Always clone the byte array as some implementations
+ // reuse the byte array (e.g. iterating using a cursor).
+ a.invokeVirtual(TypeDesc.OBJECT, "clone", TypeDesc.OBJECT, null);
+ a.checkCast(byteArrayType);
}
storePropertyValue(a, info, useWriteMethods, instanceVar, adapterInstanceClass);
diff --git a/src/main/java/com/amazon/carbonado/raw/KeyDecoder.java b/src/main/java/com/amazon/carbonado/raw/KeyDecoder.java index a14a1a3..01fb627 100644 --- a/src/main/java/com/amazon/carbonado/raw/KeyDecoder.java +++ b/src/main/java/com/amazon/carbonado/raw/KeyDecoder.java @@ -830,7 +830,7 @@ public class KeyDecoder { /**
* Decodes the given byte array which was encoded by {@link
- * KeyEncoder#encodeSingleDesc}.
+ * KeyEncoder#encodeSingleDesc}. Always returns a new byte array instance.
*/
public static byte[] decodeSingleDesc(byte[] src) throws CorruptEncodingException {
return decodeSingleDesc(src, 0, 0);
@@ -838,7 +838,7 @@ public class KeyDecoder { /**
* Decodes the given byte array which was encoded by {@link
- * KeyEncoder#encodeSingleDesc}.
+ * KeyEncoder#encodeSingleDesc}. Always returns a new byte array instance.
*
* @param prefixPadding amount of extra bytes to skip from start of encoded byte array
* @param suffixPadding amount of extra bytes to skip at end of encoded byte array
@@ -863,7 +863,8 @@ public class KeyDecoder { /**
* Decodes the given byte array which was encoded by {@link
- * KeyEncoder#encodeSingleNullableDesc}.
+ * KeyEncoder#encodeSingleNullableDesc}. Always returns a new byte array
+ * instance.
*/
public static byte[] decodeSingleNullableDesc(byte[] src) throws CorruptEncodingException {
return decodeSingleNullableDesc(src, 0, 0);
@@ -871,7 +872,8 @@ public class KeyDecoder { /**
* Decodes the given byte array which was encoded by {@link
- * KeyEncoder#encodeSingleNullableDesc}.
+ * KeyEncoder#encodeSingleNullableDesc}. Always returns a new byte array
+ * instance.
*
* @param prefixPadding amount of extra bytes to skip from start of encoded byte array
* @param suffixPadding amount of extra bytes to skip at end of encoded byte array
|