Skip to content

Commit 9cc8bbd

Browse files
committed
backport 328715d84c0eafb4fe58d28b301138374ddac168
1 parent fa91cf4 commit 9cc8bbd

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

test/hotspot/jtreg/containers/docker/TestJcmd.java

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2021, 2025, 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
@@ -37,6 +37,8 @@
3737
*/
3838
import java.util.List;
3939
import java.util.concurrent.TimeUnit;
40+
import java.util.regex.Pattern;
41+
import java.util.regex.Matcher;
4042
import java.util.stream.Collectors;
4143
import jdk.test.lib.Container;
4244
import jdk.test.lib.JDKToolFinder;
@@ -264,14 +266,16 @@ public int compareTo(PodmanVersion other) {
264266
}
265267

266268
private static PodmanVersion fromVersionString(String version) {
267-
try {
268-
// Example 'podman version 3.2.1'
269-
String versNums = version.split("\\s+", 3)[2];
270-
String[] numbers = versNums.split("\\.", 3);
271-
return new PodmanVersion(Integer.parseInt(numbers[0]),
272-
Integer.parseInt(numbers[1]),
273-
Integer.parseInt(numbers[2]));
274-
} catch (Exception e) {
269+
// Examples: 'podman version 3.2.1', 'podman version 4.9.4-rhel'
270+
final Pattern pattern = Pattern.compile("podman version (\\d+)\\.(\\d+)\\.(\\d+).*");
271+
final Matcher matcher = pattern.matcher(version);
272+
273+
if (matcher.matches()) {
274+
return new PodmanVersion(
275+
Integer.parseInt(matcher.group(1)),
276+
Integer.parseInt(matcher.group(2)),
277+
Integer.parseInt(matcher.group(3)));
278+
} else {
275279
System.out.println("Failed to parse podman version: " + version);
276280
return DEFAULT;
277281
}

0 commit comments

Comments
 (0)