Skip to content

Commit c3a5e76

Browse files
committed
Polish "Treat null as CloudPlatform.NONE"
See gh-38510
1 parent 01bb806 commit c3a5e76

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

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

Lines changed: 4 additions & 4 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.
@@ -119,14 +119,14 @@ boolean isActive(ConfigDataActivationContext activationContext) {
119119
if (activationContext == null) {
120120
return false;
121121
}
122-
boolean 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
}
126127

127128
private boolean isActive(CloudPlatform cloudPlatform) {
128-
return this.onCloudPlatform == null || this.onCloudPlatform == CloudPlatform.NONE && cloudPlatform == null
129-
|| this.onCloudPlatform == cloudPlatform;
129+
return this.onCloudPlatform == null || this.onCloudPlatform == cloudPlatform;
130130
}
131131

132132
private boolean isActive(Profiles profiles) {

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

Lines changed: 2 additions & 2 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.
@@ -100,7 +100,7 @@ void isActiveWhenSpecificCloudPlatformAgainstDifferentSpecificCloudPlatform() {
100100
}
101101

102102
@Test
103-
void isActiveWhenSpecificNoneCloudPlatformAgainstNullCloudPlatform() {
103+
void isActiveWhenNoneCloudPlatformAgainstNullCloudPlatform() {
104104
ConfigDataProperties properties = new ConfigDataProperties(NO_IMPORTS, new Activate(CloudPlatform.NONE, null));
105105
ConfigDataActivationContext context = new ConfigDataActivationContext(NULL_CLOUD_PLATFORM, NULL_PROFILES);
106106
assertThat(properties.isActive(context)).isTrue();

0 commit comments

Comments
 (0)