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

    • Type: Bug
    • Status: Resolved
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 16
    • Fix Version/s: 16
    • Component/s: core-libs
    • Environment:

      openjdk version "16-ea" 2021-03-16
      OpenJDK Runtime Environment (build 16-ea+30-2130)
      OpenJDK 64-Bit Server VM (build 16-ea+30-2130, mixed mode, sharing)

    • Resolved In Build:
      b31
    • CPU:
      x86_64
    • OS:
      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

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

                  Dates

                  Created:
                  Updated:
                  Resolved: