Browse Source

fixed JmsException/JmsUtils to fully avoid NPEs in case of cause messages being null

git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@614 50f2f4bb-b051-0410-bef5-90022cba6387
pull/1/head
Juergen Hoeller 17 years ago
parent
commit
f89bcac1a4
  1. 10
      org.springframework.jms/src/main/java/org/springframework/jms/JmsException.java
  2. 2
      org.springframework.jms/src/main/java/org/springframework/jms/listener/DefaultMessageListenerContainer.java
  3. 9
      org.springframework.jms/src/main/java/org/springframework/jms/support/JmsUtils.java

10
org.springframework.jms/src/main/java/org/springframework/jms/JmsException.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2008 the original author or authors.
* Copyright 2002-2009 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.
@ -84,8 +84,12 @@ public abstract class JmsException extends NestedRuntimeException { @@ -84,8 +84,12 @@ public abstract class JmsException extends NestedRuntimeException {
Throwable cause = getCause();
if (cause instanceof JMSException) {
Exception linkedEx = ((JMSException) cause).getLinkedException();
if (linkedEx != null && cause.getMessage().indexOf(linkedEx.getMessage()) == -1) {
message = message + "; nested exception is " + linkedEx;
if (linkedEx != null) {
String linkedMessage = linkedEx.getMessage();
String causeMessage = cause.getMessage();
if (linkedMessage != null && (causeMessage == null || !causeMessage.contains(linkedMessage))) {
message = message + "; nested exception is " + linkedEx;
}
}
}
return message;

2
org.springframework.jms/src/main/java/org/springframework/jms/listener/DefaultMessageListenerContainer.java

@ -712,7 +712,7 @@ public class DefaultMessageListenerContainer extends AbstractPollingMessageListe @@ -712,7 +712,7 @@ public class DefaultMessageListenerContainer extends AbstractPollingMessageListe
/**
* Handle the given exception that arose during setup of a listener.
* Called for every such exception in every concurrent listener.
* <p>The default implementation logs the exception at error level
* <p>The default implementation logs the exception at info level
* if not recovered yet, and at debug level if already recovered.
* Can be overridden in subclasses.
* @param ex the exception to handle

9
org.springframework.jms/src/main/java/org/springframework/jms/support/JmsUtils.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2008 the original author or authors.
* Copyright 2002-2009 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.
@ -256,8 +256,11 @@ public abstract class JmsUtils { @@ -256,8 +256,11 @@ public abstract class JmsUtils {
if (message == null) {
message = linkedEx.toString();
}
else if (!message.contains(linkedEx.getMessage())) {
message = message + "; nested exception is " + linkedEx;
else {
String linkedMessage = linkedEx.getMessage();
if (linkedMessage != null && !message.contains(linkedMessage)) {
message = message + "; nested exception is " + linkedEx;
}
}
}
return message;

Loading…
Cancel
Save