Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FISH-8728 Refine RE to allow host in jdwp agent address #6724

Merged
merged 2 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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