Skip to content

Commit

Permalink
Allow IPv6 as host in jdwp agent address
Browse files Browse the repository at this point in the history
  • Loading branch information
pzygielo committed May 18, 2024
1 parent 9473d7f commit 5a0edd9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ static boolean isJdwpOption(String option) {
}

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

static int extractDebugPort(String option) {
Matcher m = DEBUG_ADDRESS_PATTERN.matcher(option);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,27 @@ public void shouldExtractPortNumberFromDebugOptionWithHost() {
assertEquals(9876, port);
}

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

assertEquals(9876, port);
}

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

assertEquals(9876, port);
}

@Test
public void shouldExtractPortNumberFromDebugOptionWithIPv6Host() {
int port = GFLauncher.extractDebugPort("-agentlib:jdwp=transport=dt_socket,server=y,address=[fd27:2024:0518::1]: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 5a0edd9

Please sign in to comment.