Skip to content

Commit 7c52938

Browse files
committed
Polish "Fix potential NPE in GraylogExtendedLogFormatProperties"
See gh-43863
1 parent 9de5172 commit 7c52938

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/structured/GraylogExtendedLogFormatProperties.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
*/
3333
public record GraylogExtendedLogFormatProperties(String host, Service service) {
3434

35-
static final GraylogExtendedLogFormatProperties NONE = new GraylogExtendedLogFormatProperties(null, Service.NONE);
35+
static final GraylogExtendedLogFormatProperties NONE = new GraylogExtendedLogFormatProperties(null, null);
3636

3737
public GraylogExtendedLogFormatProperties(String host, Service service) {
3838
this.host = host;

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/structured/GraylogExtendedLogFormatPropertiesTests.java

+10-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ void getBindsFromEnvironmentWhenHostIsPresentAndServiceIsMissing() {
4646
MockEnvironment environment = new MockEnvironment();
4747
environment.setProperty("logging.structured.gelf.host", "spring");
4848
GraylogExtendedLogFormatProperties properties = GraylogExtendedLogFormatProperties.get(environment);
49-
assertThat(properties).isEqualTo(new GraylogExtendedLogFormatProperties("spring", Service.NONE));
49+
assertThat(properties).isEqualTo(new GraylogExtendedLogFormatProperties("spring", new Service(null)));
5050
}
5151

5252
@Test
@@ -58,6 +58,15 @@ void getBindsFromEnvironmentWhenHostIsPresentAndServiceIsMissingUsesApplicationV
5858
assertThat(properties).isEqualTo(new GraylogExtendedLogFormatProperties("spring", new Service("1.2.3")));
5959
}
6060

61+
@Test
62+
void getBindsFromEnvironmentWhenVersionIsPresentAndHostIsMissingUsesApplicationName() {
63+
MockEnvironment environment = new MockEnvironment();
64+
environment.setProperty("spring.application.name", "spring");
65+
environment.setProperty("logging.structured.gelf.service.version", "1.2.3");
66+
GraylogExtendedLogFormatProperties properties = GraylogExtendedLogFormatProperties.get(environment);
67+
assertThat(properties).isEqualTo(new GraylogExtendedLogFormatProperties("spring", new Service("1.2.3")));
68+
}
69+
6170
@Test
6271
void getWhenNoServiceNameUsesApplicationName() {
6372
MockEnvironment environment = new MockEnvironment();

0 commit comments

Comments
 (0)