Program: 162925
Project: 162925
Buggy source:
@Test public void testByteBufferDirectByteBufferMap() throws ExecutionException, InterruptedException, IOException {
  if (typeOfMap == TypeOfMap.STATELESS)   return;
  ChronicleMapBuilder<ByteBuffer,ByteBuffer> builder=ChronicleMapBuilder.of(ByteBuffer.class,ByteBuffer.class).averageKeySize(5).averageValueSize(5).entries(1000);
  try (ChronicleMap<ByteBuffer,ByteBuffer> map=newInstance(builder)){
    ByteBuffer key1=ByteBuffer.wrap(new byte[]{1,1,1,1});
    ByteBuffer key2=ByteBuffer.wrap(new byte[]{2,2,2,2});
    ByteBuffer value1=ByteBuffer.allocateDirect(4);
    value1.put(new byte[]{11,11,11,11});
    value1.flip();
    ByteBuffer value2=ByteBuffer.allocateDirect(4);
    value2.put(new byte[]{22,22,22,22});
    value2.flip();
    assertNull(map.put(key1,value1));
    assertBBEquals(value1,map.put(key1,value2));
    assertBBEquals(value2,map.get(key1));
    assertNull(map.get(key2));
    map.put(key1,value1);
    mapChecks();
    final SerializableFunction<ByteBuffer,ByteBuffer> function=new SerializableFunction<ByteBuffer,ByteBuffer>(){
      @Override public ByteBuffer apply(      ByteBuffer s){
        ByteBuffer slice=s.slice();
        slice.limit(2);
        return slice;
      }
    }
;
    assertBBEquals(ByteBuffer.wrap(new byte[]{11,11}),map.getMapped(key1,function));
    assertEquals(null,map.getMapped(key2,function));
    mapChecks();
    assertBBEquals(ByteBuffer.wrap(new byte[]{12,10}),map.putMapped(key1,new UnaryOperator<ByteBuffer>(){
      @Override public ByteBuffer update(      ByteBuffer s){
        s.put(0,(byte)(s.get(0) + 1));
        s.put(1,(byte)(s.get(1) - 1));
        return function.apply(s);
      }
    }
));
    assertBBEquals(ByteBuffer.wrap(new byte[]{12,10}),map.get(key1));
    mapChecks();
  }
 }

Fixed version (ground truth):
@Test public void testByteBufferDirectByteBufferMap() throws ExecutionException, InterruptedException, IOException {
  if (typeOfMap == TypeOfMap.STATELESS)   return;
  ChronicleMapBuilder<ByteBuffer,ByteBuffer> builder=ChronicleMapBuilder.of(ByteBuffer.class,ByteBuffer.class).averageKeySize(5).averageValueSize(5).entries(1000);
  try (ChronicleMap<ByteBuffer,ByteBuffer> map=newInstance(builder)){
    ByteBuffer key1=ByteBuffer.wrap(new byte[]{1,1,1,1});
    ByteBuffer key2=ByteBuffer.wrap(new byte[]{2,2,2,2});
    ByteBuffer value1=ByteBuffer.allocateDirect(4);
    value1.put(new byte[]{11,11,11,11});
    value1.flip();
    ByteBuffer value2=ByteBuffer.allocateDirect(4);
    value2.put(new byte[]{22,22,22,22});
    value2.flip();
    assertNull(map.put(key1,value1));
    assertBBEquals(value1,map.put(key1,value2));
    assertBBEquals(value2,map.get(key1));
    assertNull(map.get(key2));
    map.put(key1,value1);
    mapChecks();
    final SerializableFunction<ByteBuffer,ByteBuffer> function=s -> {
      ByteBuffer slice=s.slice();
      slice.limit(2);
      return slice;
    }
;
    assertBBEquals(ByteBuffer.wrap(new byte[]{11,11}),map.getMapped(key1,function));
    assertEquals(null,map.getMapped(key2,function));
    mapChecks();
    assertBBEquals(ByteBuffer.wrap(new byte[]{12,10}),map.putMapped(key1,s -> {
      s.put(0,(byte)(s.get(0) + 1));
      s.put(1,(byte)(s.get(1) - 1));
      return function.apply(s);
    }
));
    assertBBEquals(ByteBuffer.wrap(new byte[]{12,10}),map.get(key1));
    mapChecks();
  }
 }