OpenHFT / Chronicle-Map

Replicate your Key Value Store across your network, with consistency, persistance and performance.
http://chronicle.software/products/chronicle-map/
Apache License 2.0
2.79k stars 471 forks source link

ClassCastException: CompiledMapIterationContext cannot be cast to SetEntry #201

Closed danjmarques closed 4 years ago

danjmarques commented 5 years ago

I'm seeing the following exception when using version 3.17.6 of Chronicle map.

Exception in thread "main" java.lang.ClassCastException: net.openhft.chronicle.map.impl.CompiledMapIterationContext cannot be cast to net.openhft.chronicle.set.SetEntry
    at net.openhft.chronicle.set.SetFromMap.lambda$forEachEntry$1(SetFromMap.java:188)
    at net.openhft.chronicle.map.AbstractChronicleMap.lambda$forEachEntry$5(AbstractChronicleMap.java:234)
    at net.openhft.chronicle.map.impl.CompiledMapIterationContext.forEachTierEntryWhile(CompiledMapIterationContext.java:3885)
    at net.openhft.chronicle.map.impl.CompiledMapIterationContext.innerForEachSegmentEntryWhile(CompiledMapIterationContext.java:3920)
    at net.openhft.chronicle.map.impl.CompiledMapIterationContext.forEachSegmentEntryWhile(CompiledMapIterationContext.java:3940)
    at net.openhft.chronicle.map.AbstractChronicleMap.forEachEntryWhile(AbstractChronicleMap.java:244)
    at net.openhft.chronicle.map.AbstractChronicleMap.forEachEntry(AbstractChronicleMap.java:233)
    at net.openhft.chronicle.set.SetFromMap.forEachEntry(SetFromMap.java:188)

In SetFromMap.lambda$forEachEntry$1 the type of e is CompiledMapIterationContext. which is, as far as I can tell, is not a SetEntry.

Of course, it is possible that I'm doing something wrong - I've just started using this software. Sample program below:

   static class MySetEntryConsumer implements Consumer<SetEntry<LongValue>> {
        final LongValue reusableValue = Values.newHeapInstance(LongValue.class);
        long max = 0;

        @Override
        public void accept(SetEntry<LongValue> entry) {

            if (max < entry.key().getUsing(reusableValue).getValue()) {
                max = entry.key().getUsing(reusableValue).getValue();
            }
        }
    }

    public static void main(String[] args) {

        final long size = 1024 * 1024 * 16;

        try (final ChronicleSet<LongValue> mySet = ChronicleSet
                .of(LongValue.class)
                .name("my-set")
                .entries(size)
                .create()) {

            final LongValue reusableValue = Values.newHeapInstance(LongValue.class);

            for (long i = 0; i < size; i++) {
                reusableValue.setValue(i);
                mySet.add(reusableValue);
            }
            assert mySet.size() == size;

            MySetEntryConsumer mySetEntryConsumer = new MySetEntryConsumer();
            mySet.forEachEntry(mySetEntryConsumer);
            assert mySetEntryConsumer.max == size - 1;
        }
    }
dpisklov commented 4 years ago

Fixed, thanks for reporting