This is an automated email from the ASF dual-hosted git repository.

lukaszlenart pushed a commit to branch feature/WW-3576-session-map-staleness
in repository https://gitbox.apache.org/repos/asf/struts.git

commit f78c62d465e62440c52ed274d83aceffa5666d12
Author: Lukasz Lenart <[email protected]>
AuthorDate: Sun Oct 18 09:02:47 2026 +0200

    WW-3576 test(core): exercise each SessionMap operation against its own 
invalidated session
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
 .../apache/struts2/dispatcher/SessionMapTest.java  | 55 +++++++++++++++++++---
 1 file changed, 48 insertions(+), 7 deletions(-)

diff --git 
a/core/src/test/java/org/apache/struts2/dispatcher/SessionMapTest.java 
b/core/src/test/java/org/apache/struts2/dispatcher/SessionMapTest.java
index 4f182ee5e..135ca1954 100644
--- a/core/src/test/java/org/apache/struts2/dispatcher/SessionMapTest.java
+++ b/core/src/test/java/org/apache/struts2/dispatcher/SessionMapTest.java
@@ -319,21 +319,62 @@ public class SessionMapTest extends TestCase {
         assertEquals("value", read.get());
     }
 
-    public void testSessionInvalidatedElsewhereReadsAsNoSession() {
-        MockHttpServletRequest request = new MockHttpServletRequest();
-        MockHttpSession session = new MockHttpSession();
-        session.setAttribute("key", "value");
-        request.setSession(session);
-        SessionMap sessionMap = new SessionMap(request);
+    private MockHttpSession invalidatedSession;
+    private MockHttpServletRequest invalidatedRequest;
+
+    private SessionMap sessionMapOverInvalidatedSession() {
+        invalidatedRequest = new MockHttpServletRequest();
+        invalidatedSession = new MockHttpSession();
+        invalidatedSession.setAttribute("key", "value");
+        invalidatedRequest.setSession(invalidatedSession);
+        SessionMap sessionMap = new SessionMap(invalidatedRequest);
+        invalidatedSession.invalidate();
+        return sessionMap;
+    }
 
-        session.invalidate();
+    private void assertPutLandsInNewSession(SessionMap sessionMap) {
+        sessionMap.put("other", "fresh");
+
+        HttpSession current = invalidatedRequest.getSession(false);
+        assertNotNull(current);
+        assertNotSame(invalidatedSession, current);
+        assertEquals("fresh", current.getAttribute("other"));
+    }
 
+    public void testGetOnSessionInvalidatedElsewhere() {
+        SessionMap sessionMap = sessionMapOverInvalidatedSession();
         assertNull(sessionMap.get("key"));
+        assertPutLandsInNewSession(sessionMap);
+    }
+
+    public void testContainsKeyOnSessionInvalidatedElsewhere() {
+        SessionMap sessionMap = sessionMapOverInvalidatedSession();
         assertFalse(sessionMap.containsKey("key"));
+        assertPutLandsInNewSession(sessionMap);
+    }
+
+    public void testEntrySetOnSessionInvalidatedElsewhere() {
+        SessionMap sessionMap = sessionMapOverInvalidatedSession();
         assertTrue(sessionMap.entrySet().isEmpty());
+        assertPutLandsInNewSession(sessionMap);
+    }
+
+    public void testRemoveOnSessionInvalidatedElsewhere() {
+        SessionMap sessionMap = sessionMapOverInvalidatedSession();
         assertNull(sessionMap.remove("key"));
+        assertPutLandsInNewSession(sessionMap);
+    }
+
+    public void testClearOnSessionInvalidatedElsewhere() {
+        SessionMap sessionMap = sessionMapOverInvalidatedSession();
         sessionMap.clear();
+        assertPutLandsInNewSession(sessionMap);
+    }
+
+    public void testInvalidateOnSessionInvalidatedElsewhere() {
+        SessionMap sessionMap = sessionMapOverInvalidatedSession();
         sessionMap.invalidate();
+        assertPutLandsInNewSession(sessionMap);
     }
 
     public void testPutAfterInvalidationElsewhereUsesANewSession() {

Reply via email to