Skip to content

Commit

Permalink
Merge pull request payara#6724 from pzygielo/debug-option-display-jdk11+
Browse files Browse the repository at this point in the history
FISH-8728 Refine RE to allow host in jdwp agent address
  • Loading branch information
kalinchan authored and Pandrex247 committed Jul 2, 2024
1 parent d363f5c commit ffcb5c0
Show file tree
Hide file tree
Showing 2 changed files with 36 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,34 @@ 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 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 ffcb5c0

Please sign in to comment.