paulirwin commented on code in PR #1138: URL: https://github.com/apache/lucenenet/pull/1138#discussion_r1986211682
########## src/Lucene.Net/Store/MMapDirectory.cs: ########## @@ -330,15 +330,15 @@ internal virtual ByteBuffer[] Map(MMapIndexInput input, FileStream fc, long offs // LUCENENET: We get an UnauthorizedAccessException if we create a 0 byte file at the end of the range. // See: https://stackoverflow.com/a/5501331 - // We can fix this by moving back 1 byte on the offset if the bufSize is 0. - int adjust = 0; - if (bufSize == 0 && bufNr == (nrBuffers - 1) && (offset + bufferStart) > 0) + // We can fix this by using an empty ByteBuffer if the buffer size is 0. + if (bufSize == 0 && bufNr == (nrBuffers - 1)) { - adjust = 1; + buffers[bufNr] = ByteBuffer.Allocate(0).AsReadOnlyBuffer(); + break; } buffers[bufNr] = input.memoryMappedFile.CreateViewByteBuffer( - offset: (offset + bufferStart) - adjust, + offset: offset + bufferStart, Review Comment: `CreateViewByteBuffer` will already throw if negative, so that should be sufficient here. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: dev-unsubscr...@lucenenet.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org