diff --git a/activemq-broker/src/main/java/org/apache/activemq/store/SharedFileLocker.java b/activemq-broker/src/main/java/org/apache/activemq/store/SharedFileLocker.java index 56e7bde4b3..025510bc4d 100644 --- a/activemq-broker/src/main/java/org/apache/activemq/store/SharedFileLocker.java +++ b/activemq-broker/src/main/java/org/apache/activemq/store/SharedFileLocker.java @@ -99,8 +99,10 @@ public class SharedFileLocker extends AbstractLocker { @Override public void doStop(ServiceStopper stopper) throws Exception { - lockFile.unlock(); - lockFile=null; + if (lockFile != null) { + lockFile.unlock(); + lockFile = null; + } } public File getDirectory() { diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/store/SharedFileLockerTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/store/SharedFileLockerTest.java index 0c98b46335..ac8b86eb9b 100644 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/store/SharedFileLockerTest.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/store/SharedFileLockerTest.java @@ -59,6 +59,13 @@ public class SharedFileLockerTest { } + @Test + public void testStopNoStart() throws Exception { + SharedFileLocker locker1 = new SharedFileLocker(); + locker1.setDirectory(testFolder.getRoot()); + locker1.stop(); + } + @Test public void testLoop() throws Exception { // Increase the number of iterations if you are debugging races