Fix NullPointer when requesting a session that does not exist

See gh-11202
This commit is contained in:
petar.tahchiev
2017-11-29 13:53:49 +02:00
committed by Stephane Nicoll
parent 6cae9257fe
commit 35c6dc4e3b
2 changed files with 9 additions and 0 deletions

View File

@@ -60,6 +60,9 @@ public class SessionsEndpoint {
@ReadOperation
public SessionDescriptor getSession(@Selector String sessionId) {
Session session = this.sessionRepository.findById(sessionId);
if (session == null) {
return null;
}
return new SessionDescriptor(session);
}

View File

@@ -80,6 +80,12 @@ public class SessionsEndpointWebIntegrationTests {
.isEqualTo(new JSONArray().appendElement(session.getId()));
}
@Test
public void sessionForIdNotFound() {
client.get().uri((builder) -> builder.path("/actuator/sessions/some-session-id-that-does-not-exist")
.build()).exchange().expectStatus().isNotFound();
}
@Configuration
protected static class TestConfiguration {