Skip to content

Apply Nullability to spring-integration-websocket module #10195

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

anthologia
Copy link
Contributor

Related to: #10083

@@ -56,20 +59,22 @@ public class ServerWebSocketContainer extends IntegrationWebSocketContainer

private final String[] paths;

@SuppressWarnings("NullAway.Init")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be null if respective setter is not called.
Let's have Assert.notNull() before calling .setHandshakeHandler(this.handshakeHandler) in the registerWebSocketHandlers()!

private HandshakeHandler handshakeHandler;

private HandshakeInterceptor[] interceptors;
private HandshakeInterceptor @Nullable [] interceptors;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have it to be initialized to empty arrays instead?
Looks like there is a check if (!ObjectUtils.isEmpty(interceptors)) {.
However, I agree that WebSocketHandlerRegistration API has to support nulls, and for the mentioned HandshakeHandler, too.
At the same time the AbstractWebSocketHandlerRegistration does support null:

public WebSocketHandlerRegistration setHandshakeHandler(@Nullable HandshakeHandler handshakeHandler) {


private String[] origins;
private String @Nullable [] origins;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here for an empty array by default.


private boolean autoStartup = true;

private int phase = 0;

@SuppressWarnings("NullAway.Init")
private TaskScheduler sockJsTaskScheduler;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's revise this!
It indeed can be null.
Especially its getter.

@@ -324,6 +327,7 @@ else if (StompCommand.RECEIPT.equals(stompCommand)) {
}
else {
if (this.useBroker) {
Assert.notNull(this.brokerHandler, "brokerHandler is required");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is redundant.
We do have such a check in the onInit().
This method has to be marked with a @SuppressWarnings("NullAway") // Dataflow analysis limitation instead.
See more info in docs: https://docs.spring.io/spring-framework/reference/7.0/core/null-safety.html#_warnings_suppression

if (this.useBroker) {
Assert.notNull(this.brokerHandler, "brokerHandler is required");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DITTO

@@ -374,7 +379,10 @@ private void produceConnectAckMessage(Message<?> message, SimpMessageHeaderAcces
}

private void produceMessage(Message<?> message, SimpMessageHeaderAccessor headerAccessor) {
Object payload = this.messageConverter.fromMessage(message, this.payloadType.get());
Class<?> targetType = this.payloadType.get();
Assert.notNull(targetType, "payloadType must not be null");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not correct: the value of that AtomicReference is never null.
Actually, I'm thinking if it has to be an AtomicReference at all.
Can you experiment if that could be just plain Class<?> property?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants