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