BROOKLYN-225: avoid NPE in SshMachineLocation cleanup Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/46bf6b54 Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/46bf6b54 Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/46bf6b54
Branch: refs/heads/master Commit: 46bf6b54365a0bdb0f80580a95a815a6ee85b8b8 Parents: 495b1d3 Author: Aled Sage <aled.s...@gmail.com> Authored: Mon Feb 15 11:31:48 2016 +0000 Committer: Aled Sage <aled.s...@gmail.com> Committed: Mon Feb 15 11:31:48 2016 +0000 ---------------------------------------------------------------------- .../location/ssh/SshMachineLocation.java | 26 ++++++++++++-------- 1 file changed, 16 insertions(+), 10 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/46bf6b54/core/src/main/java/org/apache/brooklyn/location/ssh/SshMachineLocation.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/brooklyn/location/ssh/SshMachineLocation.java b/core/src/main/java/org/apache/brooklyn/location/ssh/SshMachineLocation.java index b059858..2ff9491 100644 --- a/core/src/main/java/org/apache/brooklyn/location/ssh/SshMachineLocation.java +++ b/core/src/main/java/org/apache/brooklyn/location/ssh/SshMachineLocation.java @@ -457,10 +457,13 @@ public class SshMachineLocation extends AbstractLocation implements MachineLocat .displayName("ssh-location cache cleaner").body(new Callable<Void>() { @Override public Void call() { try { - if (sshPoolCacheOrNull != null) sshPoolCacheOrNull.cleanUp(); + LoadingCache<Map<String, ?>, Pool<SshTool>> sshPoolCacheOrNullRef = sshPoolCacheOrNull; + Task<?> cleanupTaskRef = cleanupTask; + + if (sshPoolCacheOrNullRef != null) sshPoolCacheOrNullRef.cleanUp(); if (!SshMachineLocation.this.isManaged()) { - if (sshPoolCacheOrNull != null) sshPoolCacheOrNull.invalidateAll(); - cleanupTask.cancel(false); + if (sshPoolCacheOrNullRef != null) sshPoolCacheOrNullRef.invalidateAll(); + if (cleanupTaskRef != null) cleanupTaskRef.cancel(false); sshPoolCacheOrNull = null; } return null; @@ -486,17 +489,20 @@ public class SshMachineLocation extends AbstractLocation implements MachineLocat // we should probably expose a mechanism such as that in Entity (or re-use Entity for locations!) @Override public void close() throws IOException { - if (sshPoolCacheOrNull != null) { + LoadingCache<Map<String, ?>, Pool<SshTool>> sshPoolCacheOrNullRef = sshPoolCacheOrNull; + Task<?> cleanupTaskRef = cleanupTask; + + if (sshPoolCacheOrNullRef != null) { if (LOG.isDebugEnabled()) { - LOG.debug("{} invalidating all entries in ssh pool cache. Final stats: {}", this, sshPoolCacheOrNull.stats()); + LOG.debug("{} invalidating all entries in ssh pool cache. Final stats: {}", this, sshPoolCacheOrNullRef.stats()); } - sshPoolCacheOrNull.invalidateAll(); + sshPoolCacheOrNullRef.invalidateAll(); } - if (cleanupTask != null) { - cleanupTask.cancel(false); - cleanupTask = null; - sshPoolCacheOrNull = null; + if (cleanupTaskRef != null) { + cleanupTaskRef.cancel(false); } + cleanupTask = null; + sshPoolCacheOrNull = null; } // should not be necessary, and causes objects to be kept around a lot longer than desired