Ensure Session#getAttributeNames implementations return a copy

Currently, Session#getAttributeNames implementations, by delegating to MapSession, all return a session attribute map's key set. This causes ConcurrentModificationException when an attempt to modify session attributes is made while iterating over the returned attribute names.

Closes gh-1120
This commit is contained in:
Vedran Pavic
2018-07-17 15:05:03 +02:00
parent dba475c48f
commit 936fc853df
8 changed files with 94 additions and 3 deletions

View File

@@ -418,4 +418,17 @@ public class HazelcastSessionRepositoryTests {
verifyZeroInteractions(this.sessions);
}
@Test // gh-1120
public void getAttributeNamesAndRemove() {
HazelcastSession session = this.repository.createSession();
session.setAttribute("attribute1", "value1");
session.setAttribute("attribute2", "value2");
for (String attributeName : session.getAttributeNames()) {
session.removeAttribute(attributeName);
}
assertThat(session.getAttributeNames()).isEmpty();
}
}