While the order of the ModificationItems is indeed the order in which the actual modification takes place, making it significant in the general case, I would like to argue that it really shouldn't matter in this particular case.
I'm unable to reproduce your problem (I'm running against Apache Directory Server, which shouldn't make a difference, but admittedly Active Directory has been known to behave strangely on occations).
If I understand your problem correctly your code is similar to the following test, which works just fine for me:
Code:
protected void onSetUp() throws Exception {
DirContextAdapter adapter = new DirContextAdapter();
adapter.setAttributeValues("objectclass", new String[] { "top",
"person" });
adapter.setAttributeValue("cn", "Some Person5");
adapter.setAttributeValue("sn", "Person5");
adapter.setAttributeValues("description", new String[ {"qwe", "123", "rty", "uio"});
ldapTemplate.bind(PERSON5_DN, adapter, null);
}
public void testModifyAttributes_DirContextAdapter_MultiAttributes(){
DirContextAdapter adapter = (DirContextAdapter) ldapTemplate.lookup(PERSON5_DN);
adapter.setAttributeValues("description", new String[]{"qwe", "123", "klytt", "kalle"});
ldapTemplate.modifyAttributes(PERSON5_DN, adapter.getModificationItems());
// Verify
adapter = (DirContextAdapter) ldapTemplate.lookup(PERSON5_DN);
String[] attributes = adapter.getStringAttributes("description");
assertEquals(4, attributes.length);
assertEquals("qwe", attributes[0]);
assertEquals("123", attributes[1]);
assertEquals("klytt", attributes[2]);
assertEquals("kalle", attributes[3]);
}
The getModificationItems() above produces two ModificationItems:
* ADD_ATTRIBUTE with BasicAttribute("description") and the values "klytt" and "kalle".
* REMOVE_ATTRIBUTE with BasicAttribute("description") and the values "rty" and "uio".
Since no Attribute value already present is added the order of the ModificationItems shouldn't matter in this case.
Mabe it would help if you inspected the ModificationItems to see what is actually returned from getModificationItems(). If we can determine that the order does indeed matter due to some particular feature (defect?) in Active Directory we will of course change it, but I'd like to make sure we are actually chasing the correct problem.