Skip to content

Commit 4390497

Browse files
committed
Fix concurrency issue in Text class
After updating the Text class to use ByteBuffer in elastic#127666 we saw test failures where similar Text instances are shared between different threads and tested for equals(). The reason is that calling bytes() lazily materializes the internal ByteBuffer. That method is what the equals method calls on both instances it tests. Apparently this can leads to race conditions when instances are shared across threads. Making the internal `bytes` representation volatile fixes the problem. Closes elastic#128029
1 parent d7aebb8 commit 4390497

File tree

1 file changed

+1
-1
lines changed
  • libs/x-content/src/main/java/org/elasticsearch/xcontent

1 file changed

+1
-1
lines changed

libs/x-content/src/main/java/org/elasticsearch/xcontent/Text.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public static Text[] convertFromStringArray(String[] strings) {
3131
return texts;
3232
}
3333

34-
private ByteBuffer bytes;
34+
private volatile ByteBuffer bytes;
3535
private String text;
3636
private int hash;
3737
private int stringLength = -1;

0 commit comments

Comments
 (0)