From 0815d29e45afc36e6843704b8a25bf4f61ce2d89 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Fri, 23 Dec 2022 15:51:37 +0100 Subject: [PATCH] Defensive check for null returned from createConnection() Closes gh-29706 --- .../org/springframework/jms/support/JmsAccessor.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/spring-jms/src/main/java/org/springframework/jms/support/JmsAccessor.java b/spring-jms/src/main/java/org/springframework/jms/support/JmsAccessor.java index 03f89d28a7..a5e3ce0ed2 100644 --- a/spring-jms/src/main/java/org/springframework/jms/support/JmsAccessor.java +++ b/spring-jms/src/main/java/org/springframework/jms/support/JmsAccessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -193,7 +193,13 @@ public abstract class JmsAccessor implements InitializingBean { * @see javax.jms.ConnectionFactory#createConnection() */ protected Connection createConnection() throws JMSException { - return obtainConnectionFactory().createConnection(); + ConnectionFactory cf = obtainConnectionFactory(); + Connection con = cf.createConnection(); + if (con == null) { + throw new javax.jms.IllegalStateException( + "ConnectionFactory returned null from createConnection(): " + cf); + } + return con; } /**