Skip to content
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

Missing null checks in AbstractMessageChannel.addInterceptor/setInterceptors #25088

Closed
garyrussell opened this issue May 15, 2020 · 5 comments
Closed
Assignees
Labels
in: messaging Issues in messaging modules (jms, messaging) status: backported An issue that has been backported to maintenance branches type: enhancement A general enhancement
Milestone

Comments

@garyrussell
Copy link
Contributor

Causes downstream NPEs at runtime...

https://stackoverflow.com/questions/61828635/occassional-nullpointerexception-when-publishing-stomp-message-using-springframe/61828913#61828913

Caused by: java.lang.NullPointerException
	at org.springframework.messaging.support.AbstractMessageChannel$ChannelInterceptorChain.applyPreSend(AbstractMessageChannel.java:178)
	at org.springframework.messaging.support.AbstractMessageChannel.send(AbstractMessageChannel.java:132)
	... 2 more
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label May 15, 2020
@jhoeller
Copy link
Contributor

jhoeller commented May 16, 2020

Gary, are you asking for assertions there? Or do you expect it to ignore null values in addInterceptor?

Generally speaking, we don't necessarily add assertions for non-null arguments at this point, relying on our nullability semantics instead. It doesn't hurt to assert for it nevertheless, in particular when adding elements to internal collections.

@jhoeller jhoeller self-assigned this May 16, 2020
@jhoeller jhoeller added in: messaging Issues in messaging modules (jms, messaging) type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels May 16, 2020
@jhoeller jhoeller added this to the 5.2.7 milestone May 16, 2020
@jhoeller
Copy link
Contributor

Looking around, we tend to have assertions in individual registration methods a la addInterceptor but don't usually have them in bulk methods such as setInterceptors (where otherwise we couldn't conveniently use addAll and co). That seems sensible since collection arguments are never really meant to contain null values anywhere in Spring, whereas individual setters sometimes accept null as an indication for resetting the value. From that perspective, I'm inclinded to add an assertion to addInterceptor here while leaving setInterceptors as-is.

@garyrussell
Copy link
Contributor Author

relying on our nullability semantics instead.

Unfortunately, @Nullable annotation analysis is off by default in eclipse; I am not convinced that many developers enable it; I am not sure about IDEA.

(Not a problem with Kotlin, of course).

With collections (that can be nulled), we generally use Assert.noNullElements().

@jhoeller
Copy link
Contributor

Good point, for List<HttpMessageConverter> in RestTemplate and co, we do assert no null elements as well. I'll go for the same in AbstractMessageChannel then and will also check a few other places.

@tangmin823
Copy link

@jhoeller If you don't add null checks, there will be null exceptions.
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: messaging Issues in messaging modules (jms, messaging) status: backported An issue that has been backported to maintenance branches type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

4 participants