-
Bug
-
Resolution: Fixed
-
P3
-
16
-
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)
-
b31
-
x86_64
-
generic
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8259416 | 17 | Maurizio Cimadamore | P3 | Resolved | Fixed | b05 |
JDK-8260099 | 16.0.1 | Maurizio Cimadamore | P3 | Resolved | Fixed | b03 |
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);
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);
- backported by
-
JDK-8259416 NullPointerException in makeMappedSegment due to NULL Unmapper when length of segment is 0
-
- Resolved
-
-
JDK-8260099 NullPointerException in makeMappedSegment due to NULL Unmapper when length of segment is 0
-
- Resolved
-