Search code examples
javachroniclechronicle-map

Strange NPE from Chronicle Map toy code


I'm trying out chronicle map 2.0.0.a, and have setup a toy example map. I'd like to setup a ping-pong example where I set a value in one JVM and read from another. I'm getting a NPE calling map.get in the code below. It's strange because the map isn't null (prints out "{}" on the command line)... anyone seen this before?

    boolean target = true;
    File file = new File(...);
    ChronicleMapBuilder<Integer, Boolean> builder = ChronicleMapBuilder
            .of(Integer.class, Boolean.class);
    ChronicleMap<Integer, Boolean> map = builder.create(file);
    if (map == null) {
        System.out.println("map is null.  giving up...");
        return;
    } else {
        System.out.println("map is " + map); // this prints out "{}" 
    }

    while(! Thread.currentThread().isInterrupted()) {
        boolean currentValue = map.get(7); // NPE here...
        ...
        Thread.sleep(500);
    }

A little more information... if I add a line before the while loop to map.put(7, true), then map.get(7) throws a different exception:

Exception in thread "main" java.lang.IllegalStateException: java.lang.IllegalStateException: Unknown type ¬
at net.openhft.lang.io.AbstractBytes.readInstance(AbstractBytes.java:1909)
at net.openhft.lang.io.AbstractBytes.readEnum(AbstractBytes.java:1764)
at net.openhft.lang.io.serialization.BytesMarshallableSerializer.readSerializable(BytesMarshallableSerializer.java:109)
at net.openhft.chronicle.map.SerializationBuilder$SerializableMarshaller.read(SerializationBuilder.java:348)
at net.openhft.chronicle.map.serialization.BytesReaders$SimpleBytesReader.read(BytesReaders.java:44)
at net.openhft.chronicle.map.VanillaChronicleMap$Segment.readValue(VanillaChronicleMap.java:947)
at net.openhft.chronicle.map.VanillaChronicleMap$Segment.readValue(VanillaChronicleMap.java:940)
at net.openhft.chronicle.map.VanillaChronicleMap$Segment.onKeyPresentOnAcquire(VanillaChronicleMap.java:752)
at net.openhft.chronicle.map.VanillaChronicleMap$Segment.acquire(VanillaChronicleMap.java:710)
at net.openhft.chronicle.map.VanillaChronicleMap.lookupUsing(VanillaChronicleMap.java:373)
at net.openhft.chronicle.map.VanillaChronicleMap.get(VanillaChronicleMap.java:350)
at com.getco.risk.common.contract.Contracts.main(Contracts.java:233)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)

Caused by: java.lang.IllegalStateException: Unknown type ¬ at net.openhft.lang.io.serialization.BytesMarshallableSerializer.readSerializable(BytesMarshallableSerializer.java:119) at net.openhft.lang.io.AbstractBytes.readInstance(AbstractBytes.java:1907) ... 16 more


Solution

  • This is fixed in the following version :

    <artifactId>java-parent-pom</artifactId>
    <artifactId>chronicle-map</artifactId>
    <version>2.0.1a</version>