Skip to content

Commit 82db55c

Browse files
vpavicrwinch
authored andcommitted
Polish SessionRepositoryFilter
This commit polishes SessionRepositoryFilter by simplifying some code paths.
1 parent 1f38a93 commit 82db55c

File tree

2 files changed

+3
-11
lines changed

2 files changed

+3
-11
lines changed

spring-session-core/src/main/java/org/springframework/session/web/http/SessionRepositoryFilter.java

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2021 the original author or authors.
2+
* Copyright 2014-2022 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.
@@ -267,14 +267,7 @@ public boolean isRequestedSessionIdValid() {
267267
if (requestedSession != null) {
268268
requestedSession.setLastAccessedTime(Instant.now());
269269
}
270-
return isRequestedSessionIdValid(requestedSession);
271-
}
272-
return this.requestedSessionIdValid;
273-
}
274-
275-
private boolean isRequestedSessionIdValid(S session) {
276-
if (this.requestedSessionIdValid == null) {
277-
this.requestedSessionIdValid = session != null;
270+
this.requestedSessionIdValid = (requestedSession != null);
278271
}
279272
return this.requestedSessionIdValid;
280273
}
@@ -358,7 +351,6 @@ private S getRequestedSession() {
358351
S session = SessionRepositoryFilter.this.sessionRepository.findById(sessionId);
359352
if (session != null) {
360353
this.requestedSession = session;
361-
this.requestedSessionId = sessionId;
362354
break;
363355
}
364356
}

spring-session-core/src/test/java/org/springframework/session/web/http/SessionRepositoryFilterTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1327,7 +1327,7 @@ public void doFilter(HttpServletRequest wrappedRequest, HttpServletResponse wrap
13271327
}
13281328
});
13291329

1330-
// 2 invocations expected: initial resolution, after invalidation, after commit
1330+
// 2 invocations expected: initial resolution, after invalidation
13311331
verify(sessionRepository, times(2)).findById(eq(session.getId()));
13321332
verify(sessionRepository).deleteById(eq(session.getId()));
13331333
verify(sessionRepository).createSession();

0 commit comments

Comments
 (0)