From a68226916209d58ffd03306ebe929944f14b61c8 Mon Sep 17 00:00:00 2001 From: nsingh Date: Thu, 30 Aug 2018 12:26:18 +0200 Subject: [PATCH] PT 160096886 - Don't throw exception when actuator not available For example, when application is stopping. --- .../boot/app/cli/AbstractSpringBootApp.java | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/headless-services/commons/commons-boot-app-cli/src/main/java/org/springframework/ide/vscode/commons/boot/app/cli/AbstractSpringBootApp.java b/headless-services/commons/commons-boot-app-cli/src/main/java/org/springframework/ide/vscode/commons/boot/app/cli/AbstractSpringBootApp.java index 09733c05f..8db386a78 100644 --- a/headless-services/commons/commons-boot-app-cli/src/main/java/org/springframework/ide/vscode/commons/boot/app/cli/AbstractSpringBootApp.java +++ b/headless-services/commons/commons-boot-app-cli/src/main/java/org/springframework/ide/vscode/commons/boot/app/cli/AbstractSpringBootApp.java @@ -211,11 +211,14 @@ public abstract class AbstractSpringBootApp implements SpringBootApp { @Override public LiveBeansModel getBeans() { try { - return beansModelCache.get("liveBeans", () -> { - String domain = getDomainForActuator(); - Object json = getBeansFromActuator(domain); + // PT 160096886 - Moved actuator-based operations out of the cache because + // previous implementation was throwing exception inside the cache loader if actuator JSON was not available. + // This resulted in errors when stopping applications (i.e. when actuator was not available anymore) - if (json != null) { + String domain = getDomainForActuator(); + Object json = getBeansFromActuator(domain); + if (json != null) { + return beansModelCache.get("liveBeans", () -> { String md5 = DigestUtils.md5Hex(json.toString()); synchronized(AbstractSpringBootApp.this) { @@ -229,11 +232,11 @@ public abstract class AbstractSpringBootApp implements SpringBootApp { } return cachedBeansModel; - } - else { - throw new Exception("not getting any beans from app"); - } - }); + }); + } else { + // Actuator info not available (e.g. application stopped), return empty model. Don't return null. Causes Issues + return LiveBeansModel.builder().build(); + } } catch (Exception e) { logger.error("Error parsing beans", e); return LiveBeansModel.builder().build();