mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-11-22 06:12:05 +01:00
Fix RosterEntry.setNames(String)
also mark the method synchornized, to prevent race conditions with the name. Fixes SMACK-662.
This commit is contained in:
parent
4eb322608e
commit
65dd6c9777
1 changed files with 10 additions and 3 deletions
|
@ -94,7 +94,7 @@ public final class RosterEntry extends Manager {
|
||||||
* @throws XMPPErrorException
|
* @throws XMPPErrorException
|
||||||
* @throws NoResponseException
|
* @throws NoResponseException
|
||||||
*/
|
*/
|
||||||
public void setName(String name) throws NotConnectedException, NoResponseException, XMPPErrorException {
|
public synchronized void setName(String name) throws NotConnectedException, NoResponseException, XMPPErrorException {
|
||||||
// Do nothing if the name hasn't changed.
|
// Do nothing if the name hasn't changed.
|
||||||
if (name != null && name.equals(this.name)) {
|
if (name != null && name.equals(this.name)) {
|
||||||
return;
|
return;
|
||||||
|
@ -102,7 +102,10 @@ public final class RosterEntry extends Manager {
|
||||||
|
|
||||||
RosterPacket packet = new RosterPacket();
|
RosterPacket packet = new RosterPacket();
|
||||||
packet.setType(IQ.Type.set);
|
packet.setType(IQ.Type.set);
|
||||||
packet.addRosterItem(toRosterItem(this));
|
|
||||||
|
// Create a new roster item with the current RosterEntry and the *new* name. Note that we can't set the name of
|
||||||
|
// RosterEntry right away, as otherwise the updated event wont get fired, because equalsDeep would return true.
|
||||||
|
packet.addRosterItem(toRosterItem(this, name));
|
||||||
connection().createPacketCollectorAndSend(packet).nextResultOrThrow();
|
connection().createPacketCollectorAndSend(packet).nextResultOrThrow();
|
||||||
|
|
||||||
// We have received a result response to the IQ set, the name was successfully changed
|
// We have received a result response to the IQ set, the name was successfully changed
|
||||||
|
@ -246,7 +249,11 @@ public final class RosterEntry extends Manager {
|
||||||
}
|
}
|
||||||
|
|
||||||
static RosterPacket.Item toRosterItem(RosterEntry entry) {
|
static RosterPacket.Item toRosterItem(RosterEntry entry) {
|
||||||
RosterPacket.Item item = new RosterPacket.Item(entry.getUser(), entry.getName());
|
return toRosterItem(entry, entry.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static RosterPacket.Item toRosterItem(RosterEntry entry, String name) {
|
||||||
|
RosterPacket.Item item = new RosterPacket.Item(entry.getUser(), name);
|
||||||
item.setItemType(entry.getType());
|
item.setItemType(entry.getType());
|
||||||
item.setItemStatus(entry.getStatus());
|
item.setItemStatus(entry.getStatus());
|
||||||
// Set the correct group names for the item.
|
// Set the correct group names for the item.
|
||||||
|
|
Loading…
Reference in a new issue