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

This commit is contained in:
Juergen Hoeller 2009-02-12 17:33:57 +00:00
parent 777a104d48
commit 8669b3293c
3 changed files with 14 additions and 7 deletions

View File

@ -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 {
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;

View File

@ -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

View File

@ -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 {
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;