mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-22 20:12:07 +01:00
Make Roster API not leak internal state
Fixes SMACK-645
This commit is contained in:
parent
e9dd3e2fa6
commit
4424ec6c53
1 changed files with 11 additions and 7 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue