Skip to content

Commit f9575ac

Browse files
committed
Accept empty key's values and improve address parsing in JDWP options. (GR-67704)
1 parent e4577f1 commit f9575ac

File tree

3 files changed

+24
-25
lines changed

3 files changed

+24
-25
lines changed

espresso/src/com.oracle.truffle.espresso.jdwp/src/com/oracle/truffle/espresso/jdwp/api/JDWPOptions.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@
2828
public final class JDWPOptions {
2929
public final String transport;
3030
public final String host;
31-
public final String port;
31+
public final int port;
3232
public final boolean server;
3333
public final boolean suspend;
3434

35-
public JDWPOptions(String transport, String host, String port, boolean server, boolean suspend) {
35+
public JDWPOptions(String transport, String host, int port, boolean server, boolean suspend) {
3636
this.transport = transport;
3737
this.host = host;
3838
this.port = port;

espresso/src/com.oracle.truffle.espresso.jdwp/src/com/oracle/truffle/espresso/jdwp/impl/DebuggerController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ public boolean isServer() {
333333
}
334334

335335
public int getListeningPort() {
336-
return Integer.parseInt(options.port);
336+
return options.port;
337337
}
338338

339339
public String getHost() {

espresso/src/com.oracle.truffle.espresso/src/com/oracle/truffle/espresso/EspressoOptions.java

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -405,38 +405,37 @@ public JDWPOptions apply(String s) {
405405
final String[] options = s.split(",");
406406
String transport = null;
407407
String host = null;
408-
String port = null;
408+
int port = 0;
409409
boolean server = false;
410410
boolean suspend = true;
411411

412412
for (String keyValue : options) {
413-
String[] parts = keyValue.split("=");
414-
if (parts.length != 2) {
413+
int equalsIndex = keyValue.indexOf('=');
414+
if (equalsIndex <= 0) {
415415
throw new IllegalArgumentException("JDWP options must be a comma separated list of key=value pairs.");
416416
}
417-
String key = parts[0];
418-
String value = parts[1];
417+
String key = keyValue.substring(0, equalsIndex);
418+
String value = keyValue.substring(equalsIndex + 1);
419419
switch (key) {
420420
case "address":
421-
parts = value.split(":");
422421
String inputHost = null;
423-
String inputPort;
424-
if (parts.length == 1) {
425-
inputPort = parts[0];
426-
} else if (parts.length == 2) {
427-
inputHost = parts[0];
428-
inputPort = parts[1];
429-
} else {
430-
throw new IllegalArgumentException("Invalid JDWP option, address: " + value + ". Not a 'host:port' pair.");
431-
}
432-
long realValue;
433-
try {
434-
realValue = Long.valueOf(inputPort);
435-
if (realValue < 0 || realValue > 65535) {
436-
throw new IllegalArgumentException("Invalid JDWP option, address: " + value + ". Must be in the 0 - 65535 range.");
422+
int inputPort = 0;
423+
if (!value.isEmpty()) {
424+
int colonIndex = value.indexOf(':');
425+
if (colonIndex > 0) {
426+
inputHost = value.substring(0, colonIndex);
427+
}
428+
String portStr = value.substring(colonIndex + 1);
429+
long realValue;
430+
try {
431+
realValue = Long.valueOf(portStr);
432+
if (realValue < 0 || realValue > 65535) {
433+
throw new IllegalArgumentException("Invalid JDWP option, address: " + value + ". Must be in the 0 - 65535 range.");
434+
}
435+
} catch (NumberFormatException ex) {
436+
throw new IllegalArgumentException("Invalid JDWP option, address: " + value + ". Port is not a number. Must be a number in the 0 - 65535 range.");
437437
}
438-
} catch (NumberFormatException ex) {
439-
throw new IllegalArgumentException("Invalid JDWP option, address is not a number. Must be a number in the 0 - 65535 range.");
438+
inputPort = (int) realValue;
440439
}
441440
host = inputHost;
442441
port = inputPort;

0 commit comments

Comments
 (0)