Restore first init capability
[lgpl/argeo-commons.git] / org.argeo.security.core / src / org / argeo / util / naming / AttributesDictionary.java
index 73099ef4e414d83ecdefd364e91b11f96902ac8c..c211e8e8a40b0316d230f0d7e68cf34f0a8dfdb9 100644 (file)
@@ -120,10 +120,16 @@ public class AttributesDictionary extends Dictionary<String, Object> {
                } else {
                        if (attr.size() > 1)
                                throw new IllegalArgumentException("Attribute " + key + " is multi-valued");
-                       if (attr.size() == 1)
-                               attr.set(0, value.toString());
-                       else
+                       if (attr.size() == 1) {
+                               try {
+                                       if (!attr.get(0).equals(value))
+                                               attr.set(0, value.toString());
+                               } catch (NamingException e) {
+                                       throw new RuntimeException("Cannot check existing value", e);
+                               }
+                       } else {
                                attr.add(value.toString());
+                       }
                }
                return oldValue;
        }