From 9d0c533167518aac56c53d29655725c5ce7b77c6 Mon Sep 17 00:00:00 2001
From: Michael Zangl <michael.zangl@student.kit.edu>
Date: Fri, 27 Mar 2015 22:22:46 +0100
Subject: [PATCH] Made user map synchronized.

---
 src/org/openstreetmap/josm/data/osm/User.java | 32 +++++++++++++++------------
 1 file changed, 18 insertions(+), 14 deletions(-)

diff --git a/src/org/openstreetmap/josm/data/osm/User.java b/src/org/openstreetmap/josm/data/osm/User.java
index b87df75..481dd22 100644
--- a/src/org/openstreetmap/josm/data/osm/User.java
+++ b/src/org/openstreetmap/josm/data/osm/User.java
@@ -9,7 +9,6 @@ import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
-import java.util.concurrent.atomic.AtomicLong;
 
 import org.openstreetmap.josm.tools.Utils;
 
@@ -24,16 +23,22 @@ import org.openstreetmap.josm.tools.Utils;
  */
 public final class User {
 
-    private static AtomicLong uidCounter = new AtomicLong();
+    private static long uidCounter = 0;
 
     /**
      * the map of known users
      */
     private static Map<Long,User> userMap = new HashMap<>();
+
+    /**
+     * The anonymous user is a local user used in places where no user is known.
+     * @see #getAnonymous()
+     */
     private static final User anonymous = createLocalUser(tr("<anonymous>"));
 
     private static long getNextLocalUid() {
-        return uidCounter.decrementAndGet();
+        uidCounter--;
+        return uidCounter;
     }
 
     /**
@@ -42,12 +47,12 @@ public final class User {
      * @param name the name
      * @return a new local user with the given name
      */
-    public static User createLocalUser(String name) {
-        for(long i = -1; i >= uidCounter.get(); --i)
+    public static synchronized User createLocalUser(String name) {
+        for(long i = -1; i >= uidCounter; --i)
         {
-          User olduser = getById(i);
-          if(olduser != null && olduser.hasName(name))
-            return olduser;
+            User olduser = getById(i);
+            if(olduser != null && olduser.hasName(name))
+                return olduser;
         }
         User user = new User(getNextLocalUid(), name);
         userMap.put(user.getId(), user);
@@ -61,7 +66,7 @@ public final class User {
      * @param name the name
      * @return a new OSM user with the given name and uid
      */
-    public static User createOsmUser(long uid, String name) {
+    public static synchronized User createOsmUser(long uid, String name) {
         User user = userMap.get(uid);
         if (user == null) {
             user = new User(uid, name);
@@ -73,9 +78,8 @@ public final class User {
 
     /**
      * clears the static map of user ids to user objects
-     *
      */
-    public static void clearUserMap() {
+    public static synchronized void clearUserMap() {
         userMap.clear();
     }
 
@@ -85,8 +89,8 @@ public final class User {
      * @param uid the user id
      * @return the user; null, if there is no user with  this id
      */
-    public static User getById(long uid) {
-        return userMap.get(uid);
+    public static synchronized User getById(long uid) {
+           return userMap.get(uid);
     }
 
     /**
@@ -97,7 +101,7 @@ public final class User {
      * @return the list of users with name <code>name</code> or the empty list if
      * no such users exist
      */
-    public static List<User> getByName(String name) {
+    public static synchronized List<User> getByName(String name) {
         if (name == null) {
             name = "";
         }
-- 
1.9.1

