Skip to content

Commit b203f73

Browse files
committed
Merge pull request #43115 from izeye
* pr/43115: Fix WebServerPortFileWriter.getPortFile() without extension Closes gh-43115
2 parents 0c60e6f + dfcc7c5 commit b203f73

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/context/WebServerPortFileWriter.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,9 @@ protected File getPortFile(ApplicationContext applicationContext) {
110110
}
111111
String name = this.file.getName();
112112
String extension = StringUtils.getFilenameExtension(this.file.getName());
113-
name = name.substring(0, name.length() - extension.length() - 1);
113+
if (extension != null) {
114+
name = name.substring(0, name.length() - extension.length() - 1);
115+
}
114116
if (isUpperCase(name)) {
115117
name = name + "-" + namespace.toUpperCase(Locale.ENGLISH);
116118
}

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/context/WebServerPortFileWriterTests.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,15 @@ void createUpperCaseManagementPortFile() {
110110
assertThat(collectFileNames(file.getParentFile())).contains(managementFile);
111111
}
112112

113+
@Test
114+
void getPortFileWhenPortFileNameDoesNotHaveExtension() {
115+
File file = new File(this.tempDir, "portfile");
116+
WebServerPortFileWriter listener = new WebServerPortFileWriter(file);
117+
WebServerApplicationContext applicationContext = mock(WebServerApplicationContext.class);
118+
given(applicationContext.getServerNamespace()).willReturn("management");
119+
assertThat(listener.getPortFile(applicationContext).getName()).isEqualTo("portfile-management");
120+
}
121+
113122
private WebServerInitializedEvent mockEvent(String namespace, int port) {
114123
WebServer webServer = mock(WebServer.class);
115124
given(webServer.getPort()).willReturn(port);

0 commit comments

Comments
 (0)