Changeset 18617 in josm for trunk/src/org


Ignore:
Timestamp:
2022-12-21T19:27:55+01:00 (16 months ago)
Author:
taylor.smock
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/osm/AbstractPrimitive.java

    r18516 r18617  
    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());
     
    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);
Note: See TracChangeset for help on using the changeset viewer.