From 6163c7d8e584e854bf9a843502e3472192615967 Mon Sep 17 00:00:00 2001 From: Martijn van Groningen Date: Thu, 10 Oct 2013 17:07:31 +0200 Subject: [PATCH] Serialization improvement --- .../org/elasticsearch/index/shard/IndexShardState.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/elasticsearch/index/shard/IndexShardState.java b/src/main/java/org/elasticsearch/index/shard/IndexShardState.java index 17ae6212a7a..2b0f6047398 100644 --- a/src/main/java/org/elasticsearch/index/shard/IndexShardState.java +++ b/src/main/java/org/elasticsearch/index/shard/IndexShardState.java @@ -32,11 +32,12 @@ public enum IndexShardState { RELOCATED((byte) 4), CLOSED((byte) 5); - private static final IndexShardState[] ORDS = new IndexShardState[IndexShardState.values().length]; + private static final IndexShardState[] IDS = new IndexShardState[IndexShardState.values().length]; static { for (IndexShardState state : IndexShardState.values()) { - ORDS[state.id()] = state; + assert state.id() < IDS.length && state.id() >= 0; + IDS[state.id()] = state; } } @@ -51,9 +52,9 @@ public enum IndexShardState { } public static IndexShardState fromId(byte id) throws ElasticSearchIllegalArgumentException { - if (id < ORDS[0].id && id > ORDS[ORDS.length - 1].id) { + if (id < 0 || id >= IDS.length) { throw new ElasticSearchIllegalArgumentException("No mapping for id [" + id + "]"); } - return ORDS[id]; + return IDS[id]; } }