This is an automated email from the ASF dual-hosted git repository.
konstantinov pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/cassandra.git
The following commit(s) were added to refs/heads/trunk by this push:
new 657d9578f0 Fix version range check in
MessagingService.getVersionOrdinal
657d9578f0 is described below
commit 657d9578f0858f42caea98ffd62bce692adbf532
Author: Dmitry Konstantinov <[email protected]>
AuthorDate: Sat Aug 16 17:06:05 2025 +0100
Fix version range check in MessagingService.getVersionOrdinal
ninja: remove unused imports in CommandsForRanges to pass checkstyle
Patch by Dmitry Konstantinov; reviewed by Stefan Miklosovic, Caleb
Rackliffe for CASSANDRA-20842
---
CHANGES.txt | 1 +
src/java/org/apache/cassandra/net/MessagingService.java | 6 +++---
.../org/apache/cassandra/service/accord/CommandsForRanges.java | 1 -
.../cassandra/net/MessagingServiceOrdinaryVersionTest.java | 9 ++++++++-
4 files changed, 12 insertions(+), 5 deletions(-)
diff --git a/CHANGES.txt b/CHANGES.txt
index 8a17ee639a..eb07e60cb6 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
5.1
+ * Fix version range check in MessagingService.getVersionOrdinal
(CASSANDRA-20842)
* Allow custom constraints to be loaded via SPI (CASSANDRA-20824)
* Optimize DataPlacement lookup by ReplicationParams (CASSANDRA-20804)
* Fix ShortPaxosSimulationTest and AccordSimulationRunner do not execute from
the cli (CASSANDRA-20805)
diff --git a/src/java/org/apache/cassandra/net/MessagingService.java
b/src/java/org/apache/cassandra/net/MessagingService.java
index e209cdfb27..eef34378ed 100644
--- a/src/java/org/apache/cassandra/net/MessagingService.java
+++ b/src/java/org/apache/cassandra/net/MessagingService.java
@@ -287,7 +287,7 @@ public class MessagingService extends
MessagingServiceMBeanImpl implements Messa
}
}
static final int minVersion = Version.values()[0].value;
- static final int maxVersion = Version.values()[Version.values().length -
1].value;
+ static final int maxOrdinalVersion = Version.values().length - 1;
/**
* This is an optimisation to speed up the translation of the serialization
@@ -300,8 +300,8 @@ public class MessagingService extends
MessagingServiceMBeanImpl implements Messa
public static int getVersionOrdinal(int version)
{
int result = version - minVersion;
- if (result < 0 || result > maxVersion)
- throw new IllegalStateException("Unkown serialization version: " +
version);
+ if (result < 0 || result > maxOrdinalVersion)
+ throw new IllegalStateException("Unknown serialization version: "
+ version);
return result;
}
diff --git
a/src/java/org/apache/cassandra/service/accord/CommandsForRanges.java
b/src/java/org/apache/cassandra/service/accord/CommandsForRanges.java
index bbbb7679d3..8aa9f3dd88 100644
--- a/src/java/org/apache/cassandra/service/accord/CommandsForRanges.java
+++ b/src/java/org/apache/cassandra/service/accord/CommandsForRanges.java
@@ -33,7 +33,6 @@ import java.util.concurrent.locks.ReentrantLock;
import java.util.function.Consumer;
import javax.annotation.Nullable;
-import accord.api.Journal;
import accord.api.RoutingKey;
import accord.local.Command;
import accord.local.CommandSummaries;
diff --git
a/test/unit/org/apache/cassandra/net/MessagingServiceOrdinaryVersionTest.java
b/test/unit/org/apache/cassandra/net/MessagingServiceOrdinaryVersionTest.java
index bbe77f5fa6..33a4df3099 100644
---
a/test/unit/org/apache/cassandra/net/MessagingServiceOrdinaryVersionTest.java
+++
b/test/unit/org/apache/cassandra/net/MessagingServiceOrdinaryVersionTest.java
@@ -37,9 +37,16 @@ public class MessagingServiceOrdinaryVersionTest
MessagingService.getVersionOrdinal(1);
}
+ @Test(expected = IllegalStateException.class)
+ public void checkUnknownSmallVersionJustBeforeTheMinOne()
+ {
+ MessagingService.getVersionOrdinal(MessagingService.minVersion - 1);
+ }
+
@Test(expected = IllegalStateException.class)
public void checkUnknownBigVersion()
{
- MessagingService.getVersionOrdinal(Byte.MAX_VALUE + 1);
+ int maxVersion =
MessagingService.Version.values()[MessagingService.Version.values().length -
1].value;
+ MessagingService.getVersionOrdinal(maxVersion + 1);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]