Prevent concurrent modification exception.

This commit is contained in:
Michael Lipp 2025-01-31 12:24:21 +01:00
parent 4fc0d6fc63
commit 6a1273e701

View file

@ -140,7 +140,8 @@ public class VmPool {
* @return the string
*/
@Override
@SuppressWarnings("PMD.AvoidLiteralsInIfCondition")
@SuppressWarnings({ "PMD.AvoidLiteralsInIfCondition",
"PMD.AvoidSynchronizedStatement" })
public String toString() {
StringBuilder builder = new StringBuilder(50);
builder.append("VmPool [name=").append(name).append(", permissions=")
@ -148,8 +149,11 @@ public class VmPool {
if (vms.size() <= 3) {
builder.append(vms);
} else {
builder.append('[').append(vms.stream().limit(3).map(s -> s + ",")
.collect(Collectors.joining())).append("...]");
synchronized (vms) {
builder.append('[').append(vms.stream().limit(3)
.map(s -> s + ",").collect(Collectors.joining()))
.append("...]");
}
}
builder.append(']');
return builder.toString();