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
This commit is contained in:
Dmitry Konstantinov 2025-08-16 17:06:05 +01:00
parent fdff319739
commit 657d9578f0
4 changed files with 12 additions and 5 deletions

View File

@ -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)

View File

@ -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;
}

View File

@ -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;

View File

@ -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);
}
}