From c690231ace7c77d9843f6d1c8f32feccc1c5113c Mon Sep 17 00:00:00 2001 From: Gesly George Date: Wed, 2 Mar 2016 22:04:20 -0800 Subject: [PATCH] Tests shows ArrayIndexOutOfBoundsException when using Enums with even number of values --- .../map/ValueInterfaceWithEnumTest.java | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 src/test/java/net/openhft/chronicle/map/ValueInterfaceWithEnumTest.java diff --git a/src/test/java/net/openhft/chronicle/map/ValueInterfaceWithEnumTest.java b/src/test/java/net/openhft/chronicle/map/ValueInterfaceWithEnumTest.java new file mode 100644 index 000000000..206459564 --- /dev/null +++ b/src/test/java/net/openhft/chronicle/map/ValueInterfaceWithEnumTest.java @@ -0,0 +1,55 @@ +package net.openhft.chronicle.map; + +import net.openhft.chronicle.core.values.LongValue; +import net.openhft.chronicle.values.Values; +import org.junit.Test; + +import java.util.stream.IntStream; + +/** + * @author ges + * @since 3/2/16. + */ +public class ValueInterfaceWithEnumTest { + + /** + * This test will throw an {@link ArrayIndexOutOfBoundsException}. This seems to occur only with Enums having even number of + * values + */ + @Test + public void testValueInterface() { + LongValue longValue = Values.newHeapInstance(LongValue.class); + SimpleValueInterface simpleValueInterface = Values.newHeapInstance(SimpleValueInterface.class); + + ChronicleMap map = ChronicleMapBuilder.of(LongValue.class, SimpleValueInterface.class).entries(50).create(); + + IntStream.range(1, 20).forEach(value -> { + longValue.setValue(value); + simpleValueInterface.setId(value); + simpleValueInterface.setTruth(false); + simpleValueInterface.setSVIEnum(SimpleValueInterface.SVIEnum.SIX); + + map.put(longValue, simpleValueInterface); + }); + + IntStream.range(1, 10).forEach(value -> { + longValue.setValue(value); + SimpleValueInterface simpleValueInterface1 = map.get(longValue); + System.out.println(simpleValueInterface1.getId()); + }); + } + + public interface SimpleValueInterface { + enum SVIEnum { + ONE, TWO, THREE, FOUR, FIVE, SIX + } + + int getId(); + void setId(int id); + boolean getTruth(); + void setTruth(boolean truth); + + SVIEnum getSVIEnum(); + void setSVIEnum(SVIEnum val); + } +}