Source:
<code>private static <T, U> GenericIndexed<U> fromIterableVersionOne( Iterable<T> objectsIterable, ObjectStrategy<T> strategy, boolean allowReverseLookup, ObjectStrategy<U> resultObjectStrategy ) { Iterator<T> objects = objectsIterable.iterator(); if (!objects.hasNext()) { final ByteBuffer buffer = ByteBuffer.allocate(Ints.BYTES).putInt(0); buffer.flip(); return new GenericIndexed<>(buffer, resultObjectStrategy, allowReverseLookup); } int count = 0; HeapByteBufferWriteOutBytes headerOut = new HeapByteBufferWriteOutBytes(); HeapByteBufferWriteOutBytes valuesOut = new HeapByteBufferWriteOutBytes(); try { T prevVal = null; do { count++; T next = objects.next(); if (allowReverseLookup && prevVal != null && !(strategy.compare(prevVal, next) < 0)) { allowReverseLookup = false; } <START> <END> valuesOut.writeInt(next == null ? NULL_VALUE_SIZE_MARKER : 0); if (next != null) { strategy.writeTo(next, valuesOut); } headerOut.writeInt(Ints.checkedCast(valuesOut.size())); if (prevVal instanceof Closeable) { CloseQuietly.close((Closeable) prevVal); } prevVal = next; } while (objects.hasNext()); if (prevVal instanceof Closeable) { CloseQuietly.close((Closeable) prevVal); } } catch (IOException e) { throw new RuntimeException(e); } ByteBuffer theBuffer = ByteBuffer.allocate(Ints.checkedCast(Ints.BYTES + headerOut.size() + valuesOut.size())); theBuffer.putInt(count); headerOut.writeTo(theBuffer); valuesOut.writeTo(theBuffer); theBuffer.flip(); return new GenericIndexed<>(theBuffer.asReadOnlyBuffer(), resultObjectStrategy, allowReverseLookup); }</code><technical_language>I this design. harder remove this (in fact unused) field in future. Instead, I suggest encode nullness applying bit inverse (~) some field writing so</technical_language>

Target:
private static <T, U> GenericIndexed<U> fromIterableVersionOne( Iterable<T> objectsIterable, ObjectStrategy<T> strategy, boolean allowReverseLookup, ObjectStrategy<U> resultObjectStrategy ) { Iterator<T> objects = objectsIterable.iterator(); if (!objects.hasNext()) { final ByteBuffer buffer = ByteBuffer.allocate(Integer.BYTES).putInt(0); buffer.flip(); return new GenericIndexed<>(buffer, resultObjectStrategy, allowReverseLookup); } int count = 0; HeapByteBufferWriteOutBytes headerOut = new HeapByteBufferWriteOutBytes(); HeapByteBufferWriteOutBytes valuesOut = new HeapByteBufferWriteOutBytes(); try { T prevVal = null; do { count++; T next = objects.next(); if (allowReverseLookup && prevVal != null && !(strategy.compare(prevVal, next) < 0)) { allowReverseLookup = false; } valuesOut.writeInt(next == null ? NULL_VALUE_SIZE_MARKER : 0); if (next != null) { strategy.writeTo(next, valuesOut); } headerOut.writeInt(Ints.checkedCast(valuesOut.size())); if (prevVal instanceof Closeable) { CloseQuietly.close((Closeable) prevVal); } prevVal = next; } while (objects.hasNext()); if (prevVal instanceof Closeable) { CloseQuietly.close((Closeable) prevVal); } } catch (IOException e) { throw new RuntimeException(e); } ByteBuffer theBuffer = ByteBuffer.allocate(Ints.checkedCast(Integer.BYTES + headerOut.size() + valuesOut.size())); theBuffer.putInt(count); headerOut.writeTo(theBuffer); valuesOut.writeTo(theBuffer); theBuffer.flip(); return new GenericIndexed<>(theBuffer.asReadOnlyBuffer(), resultObjectStrategy, allowReverseLookup); }