1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-11-26 08:12:05 +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 (presence == null) {
if (unavailable != null) { if (unavailable != null) {
return unavailable; return unavailable.clone();
} }
else { else {
presence = new Presence(Presence.Type.unavailable); presence = new Presence(Presence.Type.unavailable);
@ -733,7 +733,7 @@ public class Roster extends Manager {
} }
} }
else { else {
return presence; return presence.clone();
} }
} }
} }
@ -764,7 +764,7 @@ public class Roster extends Manager {
return presence; return presence;
} }
else { else {
return presence; return presence.clone();
} }
} }
} }
@ -786,7 +786,10 @@ public class Roster extends Manager {
unavailable.setFrom(bareJid); unavailable.setFrom(bareJid);
res = new ArrayList<>(Arrays.asList(unavailable)); res = new ArrayList<>(Arrays.asList(unavailable));
} else { } else {
res = new ArrayList<>(userPresences.values()); res = new ArrayList<>(userPresences.values().size());
for (Presence presence : userPresences.values()) {
res.add(presence.clone());
}
} }
return res; return res;
} }
@ -803,6 +806,7 @@ public class Roster extends Manager {
List<Presence> res = new ArrayList<>(allPresences.size()); List<Presence> res = new ArrayList<>(allPresences.size());
for (Presence presence : allPresences) { for (Presence presence : allPresences) {
if (presence.isAvailable()) { if (presence.isAvailable()) {
// No need to clone presence here, getAllPresences already returns clones
res.add(presence); res.add(presence);
} }
} }
@ -835,7 +839,7 @@ public class Roster extends Manager {
Presence unavailable = null; Presence unavailable = null;
for (Presence presence : userPresences.values()) { for (Presence presence : userPresences.values()) {
if (presence.isAvailable()) { if (presence.isAvailable()) {
answer.add(presence); answer.add(presence.clone());
} }
else { else {
unavailable = presence; unavailable = presence;
@ -845,7 +849,7 @@ public class Roster extends Manager {
res = answer; res = answer;
} }
else if (unavailable != null) { else if (unavailable != null) {
res = Arrays.asList(unavailable); res = Arrays.asList(unavailable.clone());
} }
else { else {
Presence presence = new Presence(Presence.Type.unavailable); Presence presence = new Presence(Presence.Type.unavailable);
@ -853,7 +857,7 @@ public class Roster extends Manager {
res = Arrays.asList(presence); res = Arrays.asList(presence);
} }
} }
return Collections.unmodifiableList(res); return res;
} }
/** /**