Skip to content

Commit 8251f5a

Browse files
committed
FISH-13206 Fix TypeError: portStr.trim is not a function when debug port is a number
1 parent d237006 commit 8251f5a

2 files changed

Lines changed: 19 additions & 15 deletions

File tree

src/main/fish/payara/server/PayaraServerInstanceController.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,7 @@ export class PayaraServerInstanceController extends PayaraInstanceController {
634634
}
635635

636636

637-
public async startServer(payaraServer: PayaraLocalServerInstance, debug: boolean, debugPort: string, callback?: (status: boolean) => any): Promise<void> {
637+
public async startServer(payaraServer: PayaraLocalServerInstance, debug: boolean, debugPort: string | number | undefined, callback?: (status: boolean) => any): Promise<void> {
638638
if (!payaraServer.isStopped()) {
639639
vscode.window.showErrorMessage('Payara Server instance already running.');
640640
return;
@@ -744,7 +744,7 @@ export class PayaraServerInstanceController extends PayaraInstanceController {
744744
});
745745
}
746746

747-
private async stopAndStartInDebugMode(payaraServer: PayaraLocalServerInstance, debugPort: string, callback?: (status: boolean) => any): Promise<void> {
747+
private async stopAndStartInDebugMode(payaraServer: PayaraLocalServerInstance, debugPort: string | number | undefined, callback?: (status: boolean) => any): Promise<void> {
748748
let endpoints: RestEndpoints = new RestEndpoints(payaraServer);
749749
endpoints.invoke("stop-domain", async (_res) => {
750750
payaraServer.setState(InstanceState.STOPPED);
@@ -879,7 +879,7 @@ export class PayaraServerInstanceController extends PayaraInstanceController {
879879
this.selectListedServer(callback);
880880
}
881881
}
882-
882+
883883
public readDebugPortFromWorkspace(uri: Uri) {
884884
const workspaceFolder = vscode.workspace.getWorkspaceFolder(uri);
885885
if (workspaceFolder) {
@@ -1156,4 +1156,4 @@ interface State {
11561156
username: string;
11571157
password: string;
11581158
name: string;
1159-
}
1159+
}

src/main/fish/payara/server/start/StartTask.ts

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import { PayaraLocalServerInstance } from "../PayaraLocalServerInstance";
3434

3535
export class StartTask {
3636

37-
public startServer(payaraServer: PayaraLocalServerInstance, debug: boolean, debugPort: string): ChildProcess {
37+
public startServer(payaraServer: PayaraLocalServerInstance, debug: boolean, debugPort: string | number | undefined): ChildProcess {
3838
let jvmConfigReader: JvmConfigReader = new JvmConfigReader(payaraServer.getDomainXmlPath(), ServerUtils.DAS_NAME);
3939

4040
let javaHome: string | undefined = payaraServer.getJDKHome();
@@ -49,12 +49,12 @@ export class StartTask {
4949

5050
for (const jvmOption of jvmConfigReader.getJvmOptions()) {
5151
if (JDKVersion.isCorrectJDK(
52-
javaVersion,
53-
jvmOption.vendor,
54-
jvmOption.minVersion,
55-
jvmOption.maxVersion,
56-
jvmOption.option,
57-
javaHome)) {
52+
javaVersion,
53+
jvmOption.vendor,
54+
jvmOption.minVersion,
55+
jvmOption.maxVersion,
56+
jvmOption.option,
57+
javaHome)) {
5858

5959
optList.push(jvmOption.option);
6060
}
@@ -105,12 +105,16 @@ export class StartTask {
105105
return cp.spawn(javaVmExe, args, { cwd: payaraServer.getPath() });
106106
}
107107

108-
private isValidPort(portStr?: string): boolean {
109-
if (!portStr) {
108+
private isValidPort(portStr?: string | number): boolean {
109+
if (portStr === undefined || portStr === null || portStr === '') {
110110
return false;
111111
}
112-
const port = parseInt(portStr, 10);
113-
return portStr.trim() !== '' && port >= 0 && port <= 65535;
112+
const portString = String(portStr).trim();
113+
if (portString === '') {
114+
return false;
115+
}
116+
const port = parseInt(portString, 10);
117+
return !isNaN(port) && port >= 0 && port <= 65535;
114118
}
115119

116120
private addJavaAgent(payaraServer: PayaraLocalServerInstance, jvmConfigReader: JvmConfigReader): void {

0 commit comments

Comments
 (0)