Skip to content

Commit

Permalink
Refine RE to allow host in jdwp agent address
Browse files Browse the repository at this point in the history
  • Loading branch information
pzygielo committed May 16, 2024
1 parent 26c504b commit 9473d7f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
* only if the new code is made subject to such option by the copyright
* holder.
*/
// Portions Copyright [2016-2023] [Payara Foundation and/or its affiliates]
// Portions Copyright [2016-2024] [Payara Foundation and/or its affiliates]

package com.sun.enterprise.admin.launcher;

Expand Down Expand Up @@ -382,15 +382,17 @@ static boolean isJdwpOption(String option) {
return option.startsWith("-Xrunjdwp:") || option.startsWith("-agentlib:jdwp");
}

private static final String DEBUG_ADDRESS_PORT_GROUP = "port";
private static final Pattern DEBUG_ADDRESS_PATTERN = Pattern.compile(".*address=(?<hostWithColon>(?<host>[^:]*):)?(?<port>\\d*).*");

static int extractDebugPort(String option) {
Pattern portRegex = Pattern.compile(".*address=(?<port>\\d*).*");
Matcher m = portRegex.matcher(option);
Matcher m = DEBUG_ADDRESS_PATTERN.matcher(option);
if (!m.matches()) {
return -1;
}
try {
String addressGroup = m.group("port");
return Integer.parseInt(addressGroup);
String portGroup = m.group(DEBUG_ADDRESS_PORT_GROUP);
return Integer.parseInt(portGroup);
} catch (NumberFormatException nfex) {
return -1;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2019 Payara Foundation and/or its affiliates. All rights reserved.
* Copyright (c) 2019-2024 Payara Foundation and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
Expand Down Expand Up @@ -51,6 +51,13 @@ public void shouldExtractPortNumberFromDebugOption() {
assertEquals(9876, port);
}

@Test
public void shouldExtractPortNumberFromDebugOptionWithHost() {
int port = GFLauncher.extractDebugPort("-agentlib:jdwp=transport=dt_socket,server=y,address=*:9876,suspend=n");

assertEquals(9876, port);
}

@Test
public void shouldNotFindPortNumberInOption() {
int port = GFLauncher.extractDebugPort("-agentlib:jdwp=transport=dt_socket,server=y,suspend=n");
Expand Down

0 comments on commit 9473d7f

Please sign in to comment.