Skip to content

Commit 00f3ec1

Browse files
author
taylor.smock
committed
Fix #22580: AbstractPrimitive#putAll was not creating a copy of the keys array
This broke the RCU contract (Read-Copy-Update), since we were not modifying a ''copy'' of the array. git-svn-id: https://josm.openstreetmap.de/svn/trunk@18617 0c6e7542-c601-0410-84e7-c038aed88b3b
1 parent 3770ed9 commit 00f3ec1

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/org/openstreetmap/josm/data/osm/AbstractPrimitive.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -623,13 +623,14 @@ public void putAll(Map<String, String> tags) {
623623
return;
624624
}
625625
// Defensive copy of keys
626-
String[] newKeys = keys;
626+
final String[] tKeys = this.keys; // Used to avoid highly unlikely NPE (from a race) during clone operation.
627+
String[] newKeys = tKeys == null ? null : tKeys.clone();
627628
Map<String, String> originalKeys = getKeys();
628629
List<Map.Entry<String, String>> tagsToAdd = new ArrayList<>(tags.size());
629630
for (Map.Entry<String, String> tag : tags.entrySet()) {
630631
if (!Utils.isBlank(tag.getKey())) {
631632
int keyIndex = indexOfKey(newKeys, tag.getKey());
632-
// Realistically, we will not hit the newKeys == null branch. If it is null, keyIndex is always < 1
633+
// Realistically, we will not hit the newKeys == null branch. If it is null, keyIndex is always < 0
633634
if (keyIndex < 0 || newKeys == null) {
634635
tagsToAdd.add(tag);
635636
} else {

0 commit comments

Comments
 (0)