Ticket #19532: 19532-fix.patch

File 19532-fix.patch, 1.7 KB (added by GerdP, 4 years ago)

use atomic operation

  • src/org/openstreetmap/josm/data/osm/UniqueIdGenerator.java

     
    3939        }
    4040        idCounter.set(newId);
    4141    }
     42
     43
     44    /**
     45     * Generates a new primitive unique id. Uses the given value if that is smaller than the current id.
     46     * @param wanted the wanted id
     47     * @return long that is either equal
     48     * @since xxx
     49     */
     50    public long advanceOrGenerate(long wanted) {
     51        return idCounter.updateAndGet(x -> wanted < x ? wanted : x - 1);
     52    }
    4253}
  • src/org/openstreetmap/josm/io/AbstractReader.java

     
    622622
    623623    protected OsmPrimitive buildPrimitive(PrimitiveData pd) {
    624624        OsmPrimitive p;
    625         if (pd.getUniqueId() < pd.getIdGenerator().currentUniqueId()) {
    626             p = pd.getType().newInstance(pd.getUniqueId(), true);
    627             pd.getIdGenerator().advanceUniqueId(pd.getUniqueId());
     625        final long id = pd.getUniqueId() > 0 ? pd.getId() : pd.getIdGenerator().advanceOrGenerate(pd.getUniqueId());
     626
     627        if (id < 0) {
     628            p = pd.getType().newInstance(id, true);
    628629        } else {
    629             p = pd.getType().newVersionedInstance(pd.getId(), pd.getVersion());
     630            p = pd.getType().newVersionedInstance(id, pd.getVersion());
    630631        }
    631632        p.setVisible(pd.isVisible());
    632633        p.load(pd);