Skip to content

Commit 9afce23

Browse files
committed
WebSocketSession.getUri() may return null
Issue: SPR-15721
1 parent 930f0f1 commit 9afce23

File tree

5 files changed

+8
-5
lines changed

5 files changed

+8
-5
lines changed

spring-websocket/src/main/java/org/springframework/web/socket/WebSocketSession.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ public interface WebSocketSession extends Closeable {
4343

4444
/**
4545
* Return the URI used to open the WebSocket connection.
46+
* ({@code null} on the client side).
4647
*/
48+
@Nullable
4749
URI getUri();
4850

4951
/**

spring-websocket/src/main/java/org/springframework/web/socket/adapter/jetty/JettyWebSocketSession.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public String getId() {
103103

104104
@Override
105105
public URI getUri() {
106-
Assert.state(this.uri != null, "WebSocket session is not yet initialized");
106+
checkNativeSessionInitialized();
107107
return this.uri;
108108
}
109109

spring-websocket/src/main/java/org/springframework/web/socket/adapter/standard/StandardWebSocketSession.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public String getId() {
118118

119119
@Override
120120
public URI getUri() {
121-
Assert.state(this.uri != null, "WebSocket session is not yet initialized");
121+
checkNativeSessionInitialized();
122122
return this.uri;
123123
}
124124

spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/XhrClientSockJsSession.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ public InetSocketAddress getLocalAddress() {
7979

8080
@Override
8181
public InetSocketAddress getRemoteAddress() {
82-
return new InetSocketAddress(getUri().getHost(), getUri().getPort());
82+
URI uri = getUri();
83+
return (uri != null ? new InetSocketAddress(uri.getHost(), uri.getPort()) : null);
8384
}
8485

8586
@Override

spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/session/AbstractSockJsSession.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ private enum State {NEW, OPEN, CLOSED}
127127
public AbstractSockJsSession(String id, SockJsServiceConfig config, WebSocketHandler handler,
128128
@Nullable Map<String, Object> attributes) {
129129

130-
Assert.notNull(id, "SessionId must not be null");
131-
Assert.notNull(config, "SockJsConfig must not be null");
130+
Assert.notNull(id, "Session id must not be null");
131+
Assert.notNull(config, "SockJsServiceConfig must not be null");
132132
Assert.notNull(handler, "WebSocketHandler must not be null");
133133

134134
this.id = id;

0 commit comments

Comments
 (0)