From 1271d2ea032f234e7c83301a52845ed001c5831a Mon Sep 17 00:00:00 2001 From: Timothy Bish Date: Wed, 6 May 2015 15:13:15 -0400 Subject: [PATCH] https://issues.apache.org/jira/browse/AMQ-5758 Fix for potential NPE. --- .../util/DefaultIOExceptionHandler.java | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/activemq-broker/src/main/java/org/apache/activemq/util/DefaultIOExceptionHandler.java b/activemq-broker/src/main/java/org/apache/activemq/util/DefaultIOExceptionHandler.java index cf47f234d2..bb4e0b2bc8 100644 --- a/activemq-broker/src/main/java/org/apache/activemq/util/DefaultIOExceptionHandler.java +++ b/activemq-broker/src/main/java/org/apache/activemq/util/DefaultIOExceptionHandler.java @@ -46,8 +46,9 @@ import org.slf4j.LoggerFactory; private String noSpaceMessage = "space"; private String sqlExceptionMessage = ""; // match all private long resumeCheckSleepPeriod = 5*1000; - private AtomicBoolean handlingException = new AtomicBoolean(false); + private final AtomicBoolean handlingException = new AtomicBoolean(false); + @Override public void handle(IOException exception) { if (ignoreAllErrors) { LOG.info("Ignoring IO exception, " + exception, exception); @@ -69,10 +70,17 @@ import org.slf4j.LoggerFactory; if (ignoreSQLExceptions) { Throwable cause = exception; while (cause != null) { - String message = cause.getMessage(); - if (cause instanceof SQLException && message.contains(sqlExceptionMessage)) { - LOG.info("Ignoring SQLException, " + exception, cause); - return; + if (cause instanceof SQLException) { + String message = cause.getMessage(); + + if (message == null) { + message = ""; + } + + if (message.contains(sqlExceptionMessage)) { + LOG.info("Ignoring SQLException, " + exception, cause); + return; + } } cause = cause.getCause(); } @@ -83,6 +91,7 @@ import org.slf4j.LoggerFactory; LOG.info("Initiating stop/restart of transports on " + broker + " due to IO exception, " + exception, exception); new Thread("IOExceptionHandler: stop transports") { + @Override public void run() { try { ServiceStopper stopper = new ServiceStopper(); @@ -93,6 +102,7 @@ import org.slf4j.LoggerFactory; } finally { // resume again new Thread("IOExceptionHandler: restart transports") { + @Override public void run() { try { while (hasLockOwnership() && isPersistenceAdapterDown()) { @@ -154,6 +164,7 @@ import org.slf4j.LoggerFactory; private void stopBroker(Exception exception) { LOG.info("Stopping " + broker + " due to exception, " + exception, exception); new Thread("IOExceptionHandler: stopping " + broker) { + @Override public void run() { try { if( broker.isRestartAllowed() ) { @@ -171,6 +182,7 @@ import org.slf4j.LoggerFactory; return true; } + @Override public void setBrokerService(BrokerService broker) { this.broker = broker; }