Improve Util#requiresNettyChannelMetadata - support newer netty version (#2901)

* Improve Util#requiresNettyChannelMetadata

* Fix comment
This commit is contained in:
Peridot 2022-10-01 20:44:16 +02:00 committed by GitHub
parent d29781e0b5
commit bfc7a540cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 2 deletions

View File

@ -346,9 +346,19 @@ public class Util {
return REQUIRES_CHANNEL_METADATA = false;
try {
Integer[] parts = Iterables.toArray(
Iterables.transform(Splitter.on('.').split(version.artifactVersion()), s -> Integer.parseInt(s)),
Iterables.transform(Splitter.on('.').split(version.artifactVersion()), string -> {
// Newer versions of netty use suffix (like .Final) that can't be parsed to Integer
try {
return Integer.parseInt(string);
} catch (NumberFormatException e) {
return -1;
}
}),
int.class);
return REQUIRES_CHANNEL_METADATA = parts[0] > 4 || (parts[0] == 4 && parts[1] > 1);
int major = parts[0];
int minor = parts[1];
int patch = parts[2];
return REQUIRES_CHANNEL_METADATA = major >= 5 || major == 4 && minor > 1 || patch >= 64;
} catch (Throwable t) {
t.printStackTrace();
return REQUIRES_CHANNEL_METADATA = true;