Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8259027

NullPointerException in makeMappedSegment due to NULL Unmapper when length of segment is 0

    XMLWordPrintable

Details

    • b31
    • x86_64
    • generic

    Backports

      Description

        During development and testing a new memory mapped IO layer for Apache Lucene based on Panama (early stage of development), I figured out that MemorySegment#mapFile fails with NullPointerException, if the length of the mapped slice is 0. This is a corner case we sometimes have, but as length==0 is a supported size (annd also FileChannel#map supports it), it should work. This is stack trace:

            java.lang.NullPointerException
                at __randomizedtesting.SeedInfo.seed([DA5C56401F12B840:573A1F58076A4743]:0)
                at java.base/java.util.Objects.requireNonNull(Objects.java:208)
                at jdk.incubator.foreign/jdk.internal.foreign.MappedMemorySegmentImpl.makeMappedSegment(MappedMemorySegmentImpl.java:119)
                at jdk.incubator.foreign/jdk.incubator.foreign.MemorySegment.mapFile(MemorySegment.java:890)
                at org.apache.lucene.store.MMapDirectory.map(MMapDirectory.java:256)

        The reason for this is simple: When length is 0 (and interestingly also for some other cases), FileChannelImpl.mapInternal() returns NULL as Unmapper (which is fine). This leads to the NPE later.

        IMHO, as a MemorySegment with Length 0 does not need any unmapping, I think it should handle that case.

        Workaround in our code:
                segment = (segSize != 0L) ? MemorySegment.mapFile(path, offset + startOffset, segSize, MapMode.READ_ONLY)
                    : MemorySegment.ofArray(BytesRef.EMPTY_BYTES);

        Attachments

          Issue Links

            Activity

              People

                mcimadamore Maurizio Cimadamore
                uschindler Uwe Schindler
                Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                  Created:
                  Updated:
                  Resolved: