From 9f8d219146a789698a60bf5e98df35ddf6374fb2 Mon Sep 17 00:00:00 2001 From: Chris Beams Date: Wed, 5 Sep 2012 21:46:24 +0200 Subject: [PATCH] Remove default profile during environment merge This change fixes a minor bug with the implementation of ConfigurableEnvironment#merge, introduced in SPR-9444. During a merge of two environments A and B, where A has default profiles [prod] and B has default profiles [default] (the so-called 'reserved default profile'), B would complete the merge process having a collection of profiles reading [default, prod], which is incorrect. This commit explicitly ensure's that B's reserved default profile is removed if A has a set of default profiles greater than zero. If A consists only of [default], B will inherit it during the merge correctly; if A consists of [p1, p2], B will result in [p1, p2] as well; if B consists of [p1] and A of [p2, p3], B will result in [p1, p2, p3] post-merge. Issue: SPR-9761, SPR-9444 --- .../org/springframework/core/env/AbstractEnvironment.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/spring-core/src/main/java/org/springframework/core/env/AbstractEnvironment.java b/spring-core/src/main/java/org/springframework/core/env/AbstractEnvironment.java index 58f4d0bfe2..aa6da2d2d5 100644 --- a/spring-core/src/main/java/org/springframework/core/env/AbstractEnvironment.java +++ b/spring-core/src/main/java/org/springframework/core/env/AbstractEnvironment.java @@ -409,8 +409,11 @@ public abstract class AbstractEnvironment implements ConfigurableEnvironment { for (String profile : parent.getActiveProfiles()) { this.activeProfiles.add(profile); } - for (String profile : parent.getDefaultProfiles()) { - this.defaultProfiles.add(profile); + if (parent.getDefaultProfiles().length > 0) { + this.defaultProfiles.remove(RESERVED_DEFAULT_PROFILE_NAME); + for (String profile : parent.getDefaultProfiles()) { + this.defaultProfiles.add(profile); + } } }