1- // Copyright (c) 2020-2025 Broadcom. All Rights Reserved.
1+ // Copyright (c) 2020-2026 Broadcom. All Rights Reserved.
22// The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
33//
44// This software, the RabbitMQ Stream Java client library, is dual-licensed under the
6464import java .util .function .LongSupplier ;
6565import java .util .function .Predicate ;
6666import java .util .function .Supplier ;
67+ import java .util .regex .Matcher ;
68+ import java .util .regex .Pattern ;
6769import javax .net .ssl .X509TrustManager ;
6870import org .slf4j .Logger ;
6971import org .slf4j .LoggerFactory ;
@@ -496,20 +498,14 @@ static boolean offsetBefore(long x, long y) {
496498 return Long .compareUnsigned (x , y ) < 0 ;
497499 }
498500
499- private static String currentVersion (String currentVersion ) {
500- // versions built from source: 3.7.0+rc.1.4.gedc5d96
501- if (currentVersion .contains ("+" )) {
502- currentVersion = currentVersion .substring (0 , currentVersion .indexOf ("+" ));
503- }
504- // alpha (snapshot) versions: 3.7.0~alpha.449-1
505- if (currentVersion .contains ("~" )) {
506- currentVersion = currentVersion .substring (0 , currentVersion .indexOf ("~" ));
507- }
508- // alpha (snapshot) versions: 3.7.1-alpha.40
509- if (currentVersion .contains ("-" )) {
510- currentVersion = currentVersion .substring (0 , currentVersion .indexOf ("-" ));
501+ private static final Pattern SEMVER_PATTERN = Pattern .compile ("(\\ d+\\ .\\ d+\\ .\\ d+)" );
502+
503+ static String currentVersion (String currentVersion ) {
504+ Matcher matcher = SEMVER_PATTERN .matcher (currentVersion );
505+ if (matcher .find ()) {
506+ return matcher .group (1 );
511507 }
512- return currentVersion ;
508+ throw new IllegalArgumentException ( "No semver pattern found in: " + currentVersion ) ;
513509 }
514510
515511 /**
@@ -534,7 +530,12 @@ static int versionCompare(String str1, String str2) {
534530 }
535531
536532 static boolean is3_11_OrMore (String brokerVersion ) {
537- return versionCompare (currentVersion (brokerVersion ), "3.11.0" ) >= 0 ;
533+ try {
534+ return versionCompare (currentVersion (brokerVersion ), "3.11.0" ) >= 0 ;
535+ } catch (Exception e ) {
536+ LOGGER .debug ("Unable to parse broker version {}" , brokerVersion , e );
537+ return true ;
538+ }
538539 }
539540
540541 static Client .ClientParameters maybeSetUpClientParametersFromUris (
0 commit comments