Skip to content

Commit 9f8d219

Browse files
committed
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
1 parent f963d0f commit 9f8d219

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

spring-core/src/main/java/org/springframework/core/env/AbstractEnvironment.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,8 +409,11 @@ public void merge(ConfigurableEnvironment parent) {
409409
for (String profile : parent.getActiveProfiles()) {
410410
this.activeProfiles.add(profile);
411411
}
412-
for (String profile : parent.getDefaultProfiles()) {
413-
this.defaultProfiles.add(profile);
412+
if (parent.getDefaultProfiles().length > 0) {
413+
this.defaultProfiles.remove(RESERVED_DEFAULT_PROFILE_NAME);
414+
for (String profile : parent.getDefaultProfiles()) {
415+
this.defaultProfiles.add(profile);
416+
}
414417
}
415418
}
416419

0 commit comments

Comments
 (0)