From 48b05d2a55b27c36c661334077f6a3d22977aea4 Mon Sep 17 00:00:00 2001 From: Yanming Zhou Date: Thu, 23 Nov 2023 10:40:01 +0800 Subject: [PATCH] Treat ClouldPlatform.NONE as null Fix GH-38506 --- .../boot/context/config/ConfigDataProperties.java | 7 ++++--- .../boot/context/config/ConfigDataPropertiesTests.java | 8 ++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigDataProperties.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigDataProperties.java index 24f45d58f7b4..6edecf415475 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigDataProperties.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigDataProperties.java @@ -32,6 +32,7 @@ * * @author Phillip Webb * @author Madhura Bhave + * @author Yanming Zhou */ class ConfigDataProperties { @@ -118,14 +119,14 @@ boolean isActive(ConfigDataActivationContext activationContext) { if (activationContext == null) { return false; } - boolean activate = true; - activate = activate && isActive(activationContext.getCloudPlatform()); + boolean activate = isActive(activationContext.getCloudPlatform()); activate = activate && isActive(activationContext.getProfiles()); return activate; } private boolean isActive(CloudPlatform cloudPlatform) { - return this.onCloudPlatform == null || this.onCloudPlatform == cloudPlatform; + return this.onCloudPlatform == null || this.onCloudPlatform == CloudPlatform.NONE && cloudPlatform == null + || this.onCloudPlatform == cloudPlatform; } private boolean isActive(Profiles profiles) { diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigDataPropertiesTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigDataPropertiesTests.java index e4027f513a76..3b45e84f7e36 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigDataPropertiesTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigDataPropertiesTests.java @@ -35,6 +35,7 @@ * * @author Phillip Webb * @author Madhura Bhave + * @author Yanming Zhou */ class ConfigDataPropertiesTests { @@ -98,6 +99,13 @@ void isActiveWhenSpecificCloudPlatformAgainstDifferentSpecificCloudPlatform() { assertThat(properties.isActive(context)).isFalse(); } + @Test + void isActiveWhenSpecificNoneCloudPlatformAgainstNullCloudPlatform() { + ConfigDataProperties properties = new ConfigDataProperties(NO_IMPORTS, new Activate(CloudPlatform.NONE, null)); + ConfigDataActivationContext context = new ConfigDataActivationContext(NULL_CLOUD_PLATFORM, NULL_PROFILES); + assertThat(properties.isActive(context)).isTrue(); + } + @Test void isActiveWhenNullProfilesAgainstNullProfiles() { ConfigDataProperties properties = new ConfigDataProperties(NO_IMPORTS, new Activate(null, null));