Source:
<code>void writeIndexSegmentToFile(Offset safeEndPoint) throws IOException, StoreException { if (safeEndPoint.compareTo(startOffset) < 0) { return; } if (!safeEndPoint.equals(prevSafeEndPoint)) { if (safeEndPoint.compareTo(getEndOffset()) > 0) { throw new StoreException( "SafeEndOffSet " + safeEndPoint + " is greater than current end offset for current " + "index segment " + getEndOffset(), StoreErrorCodes.Illegal_Index_Operation); } File temp = new File(getFile().getAbsolutePath() + ".tmp"); FileOutputStream fileStream = new FileOutputStream(temp); CrcOutputStream crc = new CrcOutputStream(fileStream); DataOutputStream writer = new DataOutputStream(crc); try { rwLock.readLock().lock(); <START> writer.writeShort(version); <END> writer.writeInt(this.keySize); writer.writeInt(this.valueSize); writer.writeLong(safeEndPoint.getOffset()); if (version == PersistentIndex.VERSION_1) { writer.writeLong(lastModifiedTimeSec.get()); writer.write(resetKey.getFirst().toBytes()); writer.writeShort(resetKey.getSecond()); } for (Map.Entry<StoreKey, IndexValue> entry : index.entrySet()) { if (entry.getValue().getOffset().getOffset() + entry.getValue().getSize() <= safeEndPoint.getOffset()) { writer.write(entry.getKey().toBytes()); writer.write(entry.getValue().getBytes().array()); logger.trace("IndexSegment : writing key - value - offset size fileEndOffset {}", getFile().getAbsolutePath(), entry.getKey(), entry.getValue().getOffset(), entry.getValue().getSize(), safeEndPoint); } } prevSafeEndPoint = safeEndPoint; long crcValue = crc.getValue(); writer.writeLong(crcValue); fileStream.getChannel().force(true); temp.renameTo(getFile()); } catch (IOException e) { throw new StoreException( "IndexSegment : " + indexFile.getAbsolutePath() + " IO error while persisting index to disk", e, StoreErrorCodes.IOError); } finally { writer.close(); rwLock.readLock().unlock(); } logger.trace("IndexSegment : completed writing index to file", indexFile.getAbsolutePath()); } }</code><technical_language>line 482 - change if (safeEndPoint.compareTo(startOffset) <= 0) get a NullPointerException line 506 writer.write(resetKey.getFirst().toBytes())</technical_language>

Target:
void writeIndexSegmentToFile(Offset safeEndPoint) throws IOException, StoreException { if (safeEndPoint.compareTo(startOffset) <= 0) { return; } if (!safeEndPoint.equals(prevSafeEndPoint)) { if (safeEndPoint.compareTo(getEndOffset()) > 0) { throw new StoreException( "SafeEndOffSet " + safeEndPoint + " is greater than current end offset for current " + "index segment " + getEndOffset(), StoreErrorCodes.Illegal_Index_Operation); } File temp = new File(getFile().getAbsolutePath() + ".tmp"); FileOutputStream fileStream = new FileOutputStream(temp); CrcOutputStream crc = new CrcOutputStream(fileStream); DataOutputStream writer = new DataOutputStream(crc); try { rwLock.readLock().lock(); writer.writeShort(getVersion()); writer.writeInt(this.keySize); writer.writeInt(this.valueSize); writer.writeLong(safeEndPoint.getOffset()); if (getVersion() == PersistentIndex.VERSION_1) { writer.writeLong(lastModifiedTimeSec.get()); writer.write(resetKey.getFirst().toBytes()); writer.writeShort(resetKey.getSecond().ordinal()); } for (Map.Entry<StoreKey, IndexValue> entry : index.entrySet()) { if (entry.getValue().getOffset().getOffset() + entry.getValue().getSize() <= safeEndPoint.getOffset()) { writer.write(entry.getKey().toBytes()); writer.write(entry.getValue().getBytes().array()); logger.trace("IndexSegment : writing key - value - offset size fileEndOffset {}", getFile().getAbsolutePath(), entry.getKey(), entry.getValue().getOffset(), entry.getValue().getSize(), safeEndPoint); } } prevSafeEndPoint = safeEndPoint; long crcValue = crc.getValue(); writer.writeLong(crcValue); fileStream.getChannel().force(true); temp.renameTo(getFile()); } catch (IOException e) { throw new StoreException( "IndexSegment : " + indexFile.getAbsolutePath() + " IO error while persisting index to disk", e, StoreErrorCodes.IOError); } finally { writer.close(); rwLock.readLock().unlock(); } logger.trace("IndexSegment : completed writing index to file", indexFile.getAbsolutePath()); } }