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

JmsTemplate.convertAndSend throws NullPointerException during shutdown #29706

Closed
jmehrens opened this issue Dec 17, 2022 · 3 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

@jmehrens
Copy link

jmehrens commented Dec 17, 2022

On a web application using Spring 5.2.x the following is showing up in the log files:

 java.lang.NullPointerException
    at org.springframework.jms.support.JmsAccessor.createSession(JmsAccessor.java:208) ~[spring-jms-5.2.20.RELEASE.jar:5.2.20.RELEASE]
    at org.springframework.jms.core.JmsTemplate.execute(JmsTemplate.java:495) ~[spring-jms-5.2.20.RELEASE.jar:5.2.20.RELEASE]
    at org.springframework.jms.core.JmsTemplate.send(JmsTemplate.java:576) ~[spring-jms-5.2.20.RELEASE.jar:5.2.20.RELEASE]
    at org.springframework.jms.core.JmsTemplate.convertAndSend(JmsTemplate.java:680) ~[spring-jms-5.2.20.RELEASE.jar:5.2.20.RELEASE]
    at org.springframework.jms.core.JmsTemplate.convertAndSend(JmsTemplate.java:668) ~[spring-jms-5.2.20.RELEASE.jar:5.2.20.RELEASE]

The code that explains what is going on at a high level is JmsTemplate::execute. That code shows that the connection created by the assigned connection factory returned a null connection instead of throwing JMSException. The API contract for JmsTemplate::execute states "throws JmsException if there is any problem" but that is not true if the connection factory returned null instead of throwing JMSException.

While the root cause is the broken ConnectionFactory implementation, I think this code could be improved a bit by:

  1. Patch JmsAccessor::createConnection to throw JMSException if a connection factory returns a null connection. The error message should contain the class name of the factory that is not complying with the API spec.
  2. Patch JmsAccessor::createSession throw JMSException if the connection parameter is null.
  3. A more conservative alternative to number 1 would be to patch JmsTemplate.execute to simply check the conToClose prior to creating a session.

This issue is a low priority as these errors only occur during a shutdown of the application so impact of this issue is trivial. It just produces a confusing message in the logs.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Dec 17, 2022
@sbrannen sbrannen added in: messaging Issues in messaging modules (jms, messaging) type: enhancement A general enhancement labels Dec 17, 2022
@sbrannen sbrannen changed the title JmsTemplate.convertAndSend throws NullPointerException JmsTemplate.convertAndSend throws NullPointerException during shutdown Dec 17, 2022
@jhoeller jhoeller removed the status: waiting-for-triage An issue we've not yet triaged or decided on label Dec 19, 2022
@jhoeller jhoeller added this to the 5.3.25 milestone Dec 19, 2022
@jhoeller jhoeller self-assigned this Dec 19, 2022
@jhoeller
Copy link
Contributor

We have such defensive null-checking code for DataSource.getConnection access in spring-jdbc, so it should be feasible to do the same in spring-jms.

@jhoeller jhoeller modified the milestones: 5.3.25, 6.0.4 Dec 19, 2022
@jhoeller
Copy link
Contributor

Coming to 6.0.4 first, to be backported to 5.3.25 in a second step.

@sbrannen sbrannen added the for: backport-to-5.3.x Marks an issue as a candidate for backport to 5.3.x label Dec 19, 2022
@github-actions github-actions bot added status: backported An issue that has been backported to maintenance branches and removed for: backport-to-5.3.x Marks an issue as a candidate for backport to 5.3.x labels Dec 19, 2022
mdeinum pushed a commit to mdeinum/spring-framework that referenced this issue Jun 29, 2023
@jmehrens
Copy link
Author

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