Skip to content

Commit 77b533b

Browse files
committed
Merge pull request #38510 from quaff
* gh-38510: Polish "Treat null as CloudPlatform.NONE" Treat null as CloudPlatform.NONE Closes gh-38510
2 parents 71a1556 + c3a5e76 commit 77b533b

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
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
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2023 the original author or authors.
2+
* Copyright 2012-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -32,6 +32,7 @@
3232
*
3333
* @author Phillip Webb
3434
* @author Madhura Bhave
35+
* @author Yanming Zhou
3536
*/
3637
class ConfigDataProperties {
3738

@@ -118,8 +119,8 @@ boolean isActive(ConfigDataActivationContext activationContext) {
118119
if (activationContext == null) {
119120
return false;
120121
}
121-
boolean activate = true;
122-
activate = activate && isActive(activationContext.getCloudPlatform());
122+
CloudPlatform cloudPlatform = activationContext.getCloudPlatform();
123+
boolean activate = isActive((cloudPlatform != null) ? cloudPlatform : CloudPlatform.NONE);
123124
activate = activate && isActive(activationContext.getProfiles());
124125
return activate;
125126
}

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2023 the original author or authors.
2+
* Copyright 2012-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -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 isActiveWhenNoneCloudPlatformAgainstNullCloudPlatform() {
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)