Skip to content

Commit 01bb806

Browse files
quaffwilkinsona
authored andcommitted
Treat null as CloudPlatform.NONE
See gh-38510
1 parent 71a1556 commit 01bb806

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigDataProperties.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
*
3333
* @author Phillip Webb
3434
* @author Madhura Bhave
35+
* @author Yanming Zhou
3536
*/
3637
class ConfigDataProperties {
3738

@@ -118,14 +119,14 @@ boolean isActive(ConfigDataActivationContext activationContext) {
118119
if (activationContext == null) {
119120
return false;
120121
}
121-
boolean activate = true;
122-
activate = activate && isActive(activationContext.getCloudPlatform());
122+
boolean activate = isActive(activationContext.getCloudPlatform());
123123
activate = activate && isActive(activationContext.getProfiles());
124124
return activate;
125125
}
126126

127127
private boolean isActive(CloudPlatform cloudPlatform) {
128-
return this.onCloudPlatform == null || this.onCloudPlatform == cloudPlatform;
128+
return this.onCloudPlatform == null || this.onCloudPlatform == CloudPlatform.NONE && cloudPlatform == null
129+
|| this.onCloudPlatform == cloudPlatform;
129130
}
130131

131132
private boolean isActive(Profiles profiles) {

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigDataPropertiesTests.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
*
3636
* @author Phillip Webb
3737
* @author Madhura Bhave
38+
* @author Yanming Zhou
3839
*/
3940
class ConfigDataPropertiesTests {
4041

@@ -98,6 +99,13 @@ void isActiveWhenSpecificCloudPlatformAgainstDifferentSpecificCloudPlatform() {
9899
assertThat(properties.isActive(context)).isFalse();
99100
}
100101

102+
@Test
103+
void isActiveWhenSpecificNoneCloudPlatformAgainstNullCloudPlatform() {
104+
ConfigDataProperties properties = new ConfigDataProperties(NO_IMPORTS, new Activate(CloudPlatform.NONE, null));
105+
ConfigDataActivationContext context = new ConfigDataActivationContext(NULL_CLOUD_PLATFORM, NULL_PROFILES);
106+
assertThat(properties.isActive(context)).isTrue();
107+
}
108+
101109
@Test
102110
void isActiveWhenNullProfilesAgainstNullProfiles() {
103111
ConfigDataProperties properties = new ConfigDataProperties(NO_IMPORTS, new Activate(null, null));

0 commit comments

Comments
 (0)