1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-12-22 20:47:57 +01:00

Make Roster API not leak internal state

Fixes SMACK-645
This commit is contained in:
Florian Schmaus 2015-02-23 22:16:49 +01:00
parent e9dd3e2fa6
commit 4424ec6c53

View file

@ -724,7 +724,7 @@ public class Roster extends Manager {
}
if (presence == null) {
if (unavailable != null) {
return unavailable;
return unavailable.clone();
}
else {
presence = new Presence(Presence.Type.unavailable);
@ -733,7 +733,7 @@ public class Roster extends Manager {
}
}
else {
return presence;
return presence.clone();
}
}
}
@ -764,7 +764,7 @@ public class Roster extends Manager {
return presence;
}
else {
return presence;
return presence.clone();
}
}
}
@ -786,7 +786,10 @@ public class Roster extends Manager {
unavailable.setFrom(bareJid);
res = new ArrayList<>(Arrays.asList(unavailable));
} else {
res = new ArrayList<>(userPresences.values());
res = new ArrayList<>(userPresences.values().size());
for (Presence presence : userPresences.values()) {
res.add(presence.clone());
}
}
return res;
}
@ -803,6 +806,7 @@ public class Roster extends Manager {
List<Presence> res = new ArrayList<>(allPresences.size());
for (Presence presence : allPresences) {
if (presence.isAvailable()) {
// No need to clone presence here, getAllPresences already returns clones
res.add(presence);
}
}
@ -835,7 +839,7 @@ public class Roster extends Manager {
Presence unavailable = null;
for (Presence presence : userPresences.values()) {
if (presence.isAvailable()) {
answer.add(presence);
answer.add(presence.clone());
}
else {
unavailable = presence;
@ -845,7 +849,7 @@ public class Roster extends Manager {
res = answer;
}
else if (unavailable != null) {
res = Arrays.asList(unavailable);
res = Arrays.asList(unavailable.clone());
}
else {
Presence presence = new Presence(Presence.Type.unavailable);
@ -853,7 +857,7 @@ public class Roster extends Manager {
res = Arrays.asList(presence);
}
}
return Collections.unmodifiableList(res);
return res;
}
/**