Skip to content

Commit 6ed6c4a

Browse files
committed
Handle version parsing in RestClientBuilder (#44737)
Handle version parsing more leniently in RestClientBuilder for the cases where TLS version pinning is required since we cannot use JavaVersion here.
1 parent b8f91c4 commit 6ed6c4a

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

client/rest/src/test/java/org/elasticsearch/client/RestClientBuilderIntegTests.java

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -135,19 +135,28 @@ private static SSLContext getSslContext() throws Exception {
135135
*/
136136
private static String getProtocol() {
137137
String version = AccessController.doPrivileged((PrivilegedAction<String>) () -> System.getProperty("java.version"));
138-
String[] components = version.split("\\.");
139-
if (components.length > 0) {
140-
final int major = Integer.valueOf(components[0]);
138+
String[] parts = version.split("-");
139+
String[] numericComponents;
140+
if (parts.length == 1) {
141+
numericComponents = version.split("\\.");
142+
} else if (parts.length == 2) {
143+
numericComponents = parts[0].split("\\.");
144+
} else {
145+
throw new IllegalArgumentException("Java version string [" + version + "] could not be parsed.");
146+
}
147+
if (numericComponents.length > 0) {
148+
final int major = Integer.valueOf(numericComponents[0]);
141149
if (major < 11) {
142150
return "TLS";
143-
} if (major > 12) {
151+
}
152+
if (major > 12) {
144153
return "TLS";
145-
} else if (major == 12 && components.length > 2) {
146-
final int minor = Integer.valueOf(components[1]);
154+
} else if (major == 12 && numericComponents.length > 2) {
155+
final int minor = Integer.valueOf(numericComponents[1]);
147156
if (minor > 0) {
148157
return "TLS";
149158
} else {
150-
String patch = components[2];
159+
String patch = numericComponents[2];
151160
final int index = patch.indexOf("_");
152161
if (index > -1) {
153162
patch = patch.substring(0, index);

0 commit comments

Comments
 (0)