Changeset 8155 in josm for trunk


Ignore:
Timestamp:
2015-03-27T22:39:33+01:00 (5 years ago)
Author:
bastiK
Message:

applied #11250 - User#userMap is not synchronized (patch by michael2402)

File:
1 edited

Legend:

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

    r7005 r8155  
    1010import java.util.Map;
    1111import java.util.Set;
    12 import java.util.concurrent.atomic.AtomicLong;
    1312
    1413import org.openstreetmap.josm.tools.Utils;
     
    2524public final class User {
    2625
    27     private static AtomicLong uidCounter = new AtomicLong();
     26    private static long uidCounter = 0;
    2827
    2928    /**
     
    3130     */
    3231    private static Map<Long,User> userMap = new HashMap<>();
     32
     33    /**
     34     * The anonymous user is a local user used in places where no user is known.
     35     * @see #getAnonymous()
     36     */
    3337    private static final User anonymous = createLocalUser(tr("<anonymous>"));
    3438
    3539    private static long getNextLocalUid() {
    36         return uidCounter.decrementAndGet();
     40        uidCounter--;
     41        return uidCounter;
    3742    }
    3843
     
    4348     * @return a new local user with the given name
    4449     */
    45     public static User createLocalUser(String name) {
    46         for(long i = -1; i >= uidCounter.get(); --i)
     50    public static synchronized User createLocalUser(String name) {
     51        for(long i = -1; i >= uidCounter; --i)
    4752        {
    48           User olduser = getById(i);
    49           if(olduser != null && olduser.hasName(name))
    50             return olduser;
     53            User olduser = getById(i);
     54            if(olduser != null && olduser.hasName(name))
     55                return olduser;
    5156        }
    5257        User user = new User(getNextLocalUid(), name);
     
    6267     * @return a new OSM user with the given name and uid
    6368     */
    64     public static User createOsmUser(long uid, String name) {
     69    public static synchronized User createOsmUser(long uid, String name) {
    6570        User user = userMap.get(uid);
    6671        if (user == null) {
     
    7479    /**
    7580     * clears the static map of user ids to user objects
    76      *
    77      */
    78     public static void clearUserMap() {
     81     */
     82    public static synchronized void clearUserMap() {
    7983        userMap.clear();
    8084    }
     
    8690     * @return the user; null, if there is no user with  this id
    8791     */
    88     public static User getById(long uid) {
     92    public static synchronized User getById(long uid) {
    8993        return userMap.get(uid);
    9094    }
     
    98102     * no such users exist
    99103     */
    100     public static List<User> getByName(String name) {
     104    public static synchronized List<User> getByName(String name) {
    101105        if (name == null) {
    102106            name = "";
Note: See TracChangeset for help on using the changeset viewer.