Skip to content

Commit 2262600

Browse files
committed
Improve update handling in HazelcastSessionRepository
See gh-1106
1 parent 0c11a42 commit 2262600

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

spring-session/src/integration-test/java/org/springframework/session/hazelcast/AbstractHazelcastRepositoryITests.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2016 the original author or authors.
2+
* Copyright 2014-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -60,4 +60,17 @@ public void createAndDestroySession() {
6060
assertThat(hazelcastMap.size()).isEqualTo(0);
6161
}
6262

63+
@Test // gh-1106
64+
public void attemptToUpdateSessionAfterDelete() {
65+
HazelcastSession session = this.repository.createSession();
66+
String sessionId = session.getId();
67+
this.repository.save(session);
68+
session = this.repository.getSession(sessionId);
69+
session.setAttribute("attributeName", "attributeValue");
70+
this.repository.delete(sessionId);
71+
this.repository.save(session);
72+
73+
assertThat(this.repository.getSession(sessionId)).isNull();
74+
}
75+
6376
}

spring-session/src/main/java/org/springframework/session/hazelcast/HazelcastSessionRepository.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,9 @@ private static final class SessionUpdateEntryProcessor
399399

400400
public Object process(Map.Entry<String, MapSession> entry) {
401401
MapSession value = entry.getValue();
402+
if (value == null) {
403+
return Boolean.FALSE;
404+
}
402405
value.setLastAccessedTime(this.lastAccessedTime);
403406
value.setMaxInactiveIntervalInSeconds(this.maxInactiveIntervalInSeconds);
404407
for (final Map.Entry<String, Object> attribute : this.delta.entrySet()) {
@@ -410,7 +413,7 @@ public Object process(Map.Entry<String, MapSession> entry) {
410413
}
411414
}
412415
entry.setValue(value);
413-
return value;
416+
return Boolean.TRUE;
414417
}
415418

416419
}

0 commit comments

Comments
 (0)