Skip to content

Commit 2ccdefc

Browse files
committed
8299470: sun/jvm/hotspot/SALauncher.java handling of negative rmiport args
Reviewed-by: clanger, sspitsyn, kevinw
1 parent 578c287 commit 2ccdefc

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/SAGetopt.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -59,7 +59,8 @@ private void extractOptarg(String opt) {
5959
}
6060

6161
if (! _argv[_optind].isEmpty() && _argv[_optind].charAt(0) == '-') {
62-
throw new SAGetoptException("Argument is expected for '" + opt + "'");
62+
throw new SAGetoptException("Successor argument without leading - is expected for '" + opt +
63+
"' but we got '" + _argv[_optind] + "'");
6364
}
6465

6566
_optarg = _argv[_optind];

src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/SALauncher.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -500,7 +500,8 @@ public static void main(String[] args) {
500500
func.accept(oldArgs);
501501
}
502502
} catch (SAGetoptException e) {
503-
System.err.println(e.getMessage());
503+
System.err.println("SA agent option related exception occurred: " + e.getMessage());
504+
e.printStackTrace();
504505
toolHelp(args[0]);
505506
// Exit with error status
506507
System.exit(1);

test/hotspot/jtreg/serviceability/sa/sadebugd/SADebugDTest.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2016, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2016, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -101,12 +101,18 @@ private static void testWithPid(final boolean useRmiPort, final boolean useRegis
101101
int registryPort = REGISTRY_DEFAULT_PORT;
102102
if (useRegistryPort) {
103103
registryPort = Utils.findUnreservedFreePort(REGISTRY_DEFAULT_PORT);
104+
if (registryPort == -1) {
105+
throw new RuntimeException("Cannot find a registryPort, findUnreservedFreePort returns -1");
106+
}
104107
jhsdbLauncher.addToolArg("--registryport");
105108
jhsdbLauncher.addToolArg(Integer.toString(registryPort));
106109
}
107110

108111
final int rmiPort = useRmiPort ? Utils.findUnreservedFreePort(REGISTRY_DEFAULT_PORT, registryPort) : -1;
109112
if (useRmiPort) {
113+
if (rmiPort == -1) {
114+
throw new RuntimeException("Cannot find an rmiPort, findUnreservedFreePort returns -1");
115+
}
110116
jhsdbLauncher.addToolArg("--rmiport");
111117
jhsdbLauncher.addToolArg(Integer.toString(rmiPort));
112118
}

0 commit comments

Comments
 (0)