diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/ReleaseService.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/ReleaseService.java index 6e1e25d7040..0911ddd4c7a 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/ReleaseService.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/ReleaseService.java @@ -33,6 +33,7 @@ import com.ctrip.framework.apollo.common.exception.NotFoundException; import com.ctrip.framework.apollo.common.utils.GrayReleaseRuleItemTransformer; import com.ctrip.framework.apollo.core.utils.StringUtils; +import com.google.common.base.Strings; import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.google.common.collect.Sets; @@ -61,7 +62,7 @@ public class ReleaseService { .newHashSet(ReleaseOperation.GRAY_RELEASE, ReleaseOperation.MASTER_NORMAL_RELEASE_MERGE_TO_GRAY, ReleaseOperation.MATER_ROLLBACK_MERGE_TO_GRAY); private static final Pageable FIRST_ITEM = PageRequest.of(0, 1); - private static final Type OPERATION_CONTEXT_TYPE_REFERENCE = new TypeToken>() { }.getType(); + private static final Type OPERATION_CONTEXT_TYPE_REFERENCE = new TypeToken>>() { }.getType(); private final ReleaseRepository releaseRepository; private final ItemService itemService; @@ -322,14 +323,20 @@ private Collection getBranchReleaseKeys(long releaseId) { return null; } - Map operationContext = GSON - .fromJson(releaseHistories.getContent().get(0).getOperationContext(), OPERATION_CONTEXT_TYPE_REFERENCE); + String operationContextJson = releaseHistories.getContent().get(0).getOperationContext(); + if (Strings.isNullOrEmpty(operationContextJson) + || !operationContextJson.contains(ReleaseOperationContext.BRANCH_RELEASE_KEYS)) { + return null; + } - if (operationContext == null || !operationContext.containsKey(ReleaseOperationContext.BRANCH_RELEASE_KEYS)) { + Map> operationContext = GSON + .fromJson(operationContextJson, OPERATION_CONTEXT_TYPE_REFERENCE); + + if (operationContext == null) { return null; } - return (Collection) operationContext.get(ReleaseOperationContext.BRANCH_RELEASE_KEYS); + return operationContext.get(ReleaseOperationContext.BRANCH_RELEASE_KEYS); } private Release publishBranchNamespace(Namespace parentNamespace, Namespace childNamespace, @@ -396,21 +403,18 @@ private Release branchRelease(Namespace parentNamespace, Namespace childNamespac private Map mergeConfiguration(Map baseConfigurations, Map coverConfigurations) { - Map result = new LinkedHashMap<>(); + int expectedSize = baseConfigurations.size() + coverConfigurations.size(); + Map result = Maps.newLinkedHashMapWithExpectedSize(expectedSize); + //copy base configuration - for (Map.Entry entry : baseConfigurations.entrySet()) { - result.put(entry.getKey(), entry.getValue()); - } + result.putAll(baseConfigurations); //update and publish - for (Map.Entry entry : coverConfigurations.entrySet()) { - result.put(entry.getKey(), entry.getValue()); - } + result.putAll(coverConfigurations); return result; } - private Map getNamespaceItems(Namespace namespace) { List items = itemService.findItemsWithOrdered(namespace.getId()); Map configurations = new LinkedHashMap<>();