Skip to content

Commit 891d292

Browse files
vancexumeiliang86
authored andcommitted
Fix empty result when get twice from search attributes (#412)
1 parent 7dd8476 commit 891d292

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/main/java/com/uber/cadence/workflow/WorkflowUtils.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,10 @@ public static <T> T getValueFromSearchAttributes(
3636

3737
private static byte[] getValueBytes(SearchAttributes searchAttributes, String key) {
3838
ByteBuffer byteBuffer = searchAttributes.getIndexedFields().get(key);
39-
final byte[] valueBytes = new byte[byteBuffer.limit() - byteBuffer.position()];
40-
byteBuffer.get(valueBytes, 0, valueBytes.length);
39+
final byte[] valueBytes = new byte[byteBuffer.remaining()];
40+
byteBuffer.mark();
41+
byteBuffer.get(valueBytes);
42+
byteBuffer.reset();
4143
return valueBytes;
4244
}
4345
}

src/test/java/com/uber/cadence/workflow/WorkflowUtilsTest.java

+16
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,20 @@ public void TestGetValueFromSearchAttributes() {
6161
WorkflowUtils.getValueFromSearchAttributes(
6262
searchAttributes, "CustomBooleanField", Boolean.class));
6363
}
64+
65+
@Test
66+
public void TestGetValueFromSearchAttributesRepeated() {
67+
Map<String, Object> attr = new HashMap<>();
68+
String stringVal = "keyword";
69+
attr.put("CustomKeywordField", stringVal);
70+
SearchAttributes searchAttributes = InternalUtils.convertMapToSearchAttributes(attr);
71+
assertEquals(
72+
stringVal,
73+
WorkflowUtils.getValueFromSearchAttributes(
74+
searchAttributes, "CustomKeywordField", String.class));
75+
assertEquals(
76+
stringVal,
77+
WorkflowUtils.getValueFromSearchAttributes(
78+
searchAttributes, "CustomKeywordField", String.class));
79+
}
6480
}

0 commit comments

Comments
 (0)