Skip to content

Commit 622c743

Browse files
committed
8360533: ContainerRuntimeVersionTestUtils fromVersionString fails with some docker versions
Backport-of: 97ec9d3e0a6e3455579b567e1f58026f5b168c09
1 parent 94b6b99 commit 622c743

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

test/lib/jdk/test/lib/containers/docker/ContainerRuntimeVersionTestUtils.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,21 @@ public static ContainerRuntimeVersionTestUtils fromVersionString(String version)
7979
try {
8080
// Example 'docker version 20.10.0 or podman version 4.9.4-rhel'
8181
String versNums = version.split("\\s+", 3)[2];
82+
// On some docker implementations e.g. RHEL8 ppc64le we have the following version output:
83+
// Docker version v25.0.3, build 4debf41
84+
// Trim potentially leading 'v' and trailing ','
85+
if (versNums.startsWith("v")) {
86+
versNums = versNums.substring(1);
87+
}
88+
int cidx = versNums.indexOf(',');
89+
versNums = (cidx != -1) ? versNums.substring(0, cidx) : versNums;
90+
8291
String[] numbers = versNums.split("-")[0].split("\\.", 3);
8392
return new ContainerRuntimeVersionTestUtils(Integer.parseInt(numbers[0]),
8493
Integer.parseInt(numbers[1]),
8594
Integer.parseInt(numbers[2]));
8695
} catch (Exception e) {
87-
throw new RuntimeException("Failed to parse container runtime version: " + version);
96+
throw new RuntimeException("Failed to parse container runtime version: " + version, e);
8897
}
8998
}
9099

@@ -104,4 +113,4 @@ public static String getContainerRuntimeVersionStr() {
104113
public static ContainerRuntimeVersionTestUtils getContainerRuntimeVersion() {
105114
return ContainerRuntimeVersionTestUtils.fromVersionString(getContainerRuntimeVersionStr());
106115
}
107-
}
116+
}

0 commit comments

Comments
 (0)