This is an automated email from the ASF dual-hosted git repository. heneveld pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/brooklyn-server.git
commit 4824712c9fd88414fc59a87f028161930080602f Author: Alex Heneveld <[email protected]> AuthorDate: Fri Sep 10 12:46:38 2021 +0100 add null check for better behaviour in edge case --- .../BrooklynMementoPersisterToObjectStore.java | 30 ++++++++++++---------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/core/src/main/java/org/apache/brooklyn/core/mgmt/persist/BrooklynMementoPersisterToObjectStore.java b/core/src/main/java/org/apache/brooklyn/core/mgmt/persist/BrooklynMementoPersisterToObjectStore.java index 80ada41..3ae3bc9 100644 --- a/core/src/main/java/org/apache/brooklyn/core/mgmt/persist/BrooklynMementoPersisterToObjectStore.java +++ b/core/src/main/java/org/apache/brooklyn/core/mgmt/persist/BrooklynMementoPersisterToObjectStore.java @@ -336,21 +336,25 @@ public class BrooklynMementoPersisterToObjectStore implements BrooklynMementoPer Exceptions.propagateIfFatal(e); exceptionHandler.onLoadMementoFailed(type, "memento "+id+" read error", e); } - - String xmlId = (String) XmlUtil.xpathHandlingIllegalChars(contents, "/"+type.toCamelCase()+"/id"); - String safeXmlId = Strings.makeValidFilename(xmlId); - if (!Objects.equal(id, safeXmlId)) - LOG.warn("ID mismatch on "+type.toCamelCase()+", "+id+" from path, "+safeXmlId+" from xml"); - - if (type == BrooklynObjectType.MANAGED_BUNDLE) { - // TODO could R/W to cache space directly, rather than memory copy then extra file copy - byte[] jarData = readBytes(contentsSubpath+".jar"); - if (jarData==null) { - throw new IllegalStateException("No bundle data for "+contentsSubpath); + if (contents==null) { + LOG.warn("No contents for "+contentsSubpath+" in persistence store; ignoring"); + + } else { + String xmlId = (String) XmlUtil.xpathHandlingIllegalChars(contents, "/" + type.toCamelCase() + "/id"); + String safeXmlId = Strings.makeValidFilename(xmlId); + if (!Objects.equal(id, safeXmlId)) + LOG.warn("ID mismatch on " + type.toCamelCase() + ", " + id + " from path, " + safeXmlId + " from xml"); + + if (type == BrooklynObjectType.MANAGED_BUNDLE) { + // TODO could R/W to cache space directly, rather than memory copy then extra file copy + byte[] jarData = readBytes(contentsSubpath + ".jar"); + if (jarData == null) { + throw new IllegalStateException("No bundle data for " + contentsSubpath); + } + builder.bundleJar(id, ByteSource.wrap(jarData)); } - builder.bundleJar(id, ByteSource.wrap(jarData)); + builder.put(type, xmlId, contents); } - builder.put(type, xmlId, contents); } };
