Program: 93866
Project: 93866
Buggy source:
@Test public void testDirectAddOrReplace() throws Exception {
  try (OHCache<Integer,String> cache=OHCacheBuilder.<Integer,String>newBuilder().keySerializer(TestUtils.intSerializer).valueSerializer(TestUtils.stringSerializer).capacity(64 * 1024 * 1024).build()){
    for (int i=0; i < 100; i++) {
      Assert.assertNull(cache.addOrReplaceDirect(i,null,i + 10));
      DirectValueAccess direct=cache.putIfAbsentDirect(i,i + 10);
      try {
        for (int j=0; j < 100; j++)         Assert.assertNull(cache.getDirect(i));
        for (int c=0; c < i + 10; c++)         direct.buffer().put((byte)i);
      }
  finally {
        Assert.assertTrue(direct.commit());
      }
    }
    for (int i=0; i < 100; i++) {
      try (DirectValueAccess ex=cache.getDirect(i)){
        Assert.assertNotNull(ex);
        DirectValueAccess direct=cache.addOrReplaceDirect(i,ex,i + 10);
        try {
          for (int c=0; c < i + 10; c++)           direct.buffer().put((byte)i);
        }
  finally {
          Assert.assertTrue(direct.commit());
        }
      }
     }
    for (int i=0; i < 100; i++) {
      DirectValueAccess direct=cache.addOrReplaceDirect(i,null,i + 10);
      try {
        for (int c=0; c < i + 10; c++)         direct.buffer().put((byte)i);
      }
  finally {
        Assert.assertTrue(direct.commit());
      }
    }
  }
 }

Fixed version (ground truth):
@Test public void testDirectAddOrReplace() throws Exception {
  try (OHCache<Integer,String> cache=OHCacheBuilder.<Integer,String>newBuilder().keySerializer(TestUtils.intSerializer).valueSerializer(TestUtils.stringSerializer).capacity(64 * 1024 * 1024).build()){
    for (int i=0; i < 100; i++) {
      Assert.assertNull(cache.addOrReplaceDirect(i,null,i + 10));
      DirectValueAccess direct=cache.putIfAbsentDirect(i,i + 10);
      try {
        for (int j=0; j < 100; j++)         Assert.assertNull(cache.getDirect(i));
        for (int c=0; c < i + 10; c++)         direct.buffer().put((byte)i);
      }
  finally {
        Assert.assertTrue(direct.commit());
      }
      Assert.assertNull(cache.putIfAbsentDirect(i,i + 10));
    }
    cache.clear();
    for (int i=0; i < 100; i++) {
      Assert.assertNull(cache.addOrReplaceDirect(i,null,i + 10));
      DirectValueAccess direct=cache.putIfAbsentDirect(i,i + 10);
      try {
        try (DirectValueAccess conc=cache.putDirect(i,i + 10)){
          for (int c=0; c < i + 10; c++)           conc.buffer().put((byte)i);
        }
         for (int j=0; j < 100; j++)         try (DirectValueAccess chk=cache.getDirect(i)){
          Assert.assertNotNull(chk);
        }
         for (int c=0; c < i + 10; c++)         direct.buffer().put((byte)i);
      }
  finally {
        Assert.assertFalse(direct.commit());
      }
      Assert.assertNull(cache.putIfAbsentDirect(i,i + 10));
    }
    for (int i=0; i < 100; i++) {
      try (DirectValueAccess ex=cache.getDirect(i)){
        Assert.assertNotNull(ex);
        DirectValueAccess direct=cache.addOrReplaceDirect(i,ex,i + 10);
        try {
          for (int c=0; c < i + 10; c++)           direct.buffer().put((byte)i);
        }
  finally {
          Assert.assertTrue(direct.commit());
        }
      }
     }
    for (int i=0; i < 100; i++) {
      try (DirectValueAccess ex=cache.getDirect(i)){
        Assert.assertNotNull(ex);
        cache.put(i,"String_Node_Str" + i);
        DirectValueAccess direct=cache.addOrReplaceDirect(i,ex,i + 10);
        try {
          for (int c=0; c < i + 10; c++)           direct.buffer().put((byte)i);
        }
  finally {
          Assert.assertFalse(direct.commit());
        }
        Assert.assertEquals(cache.get(i),"String_Node_Str" + i);
      }
     }
    for (int i=0; i < 100; i++) {
      DirectValueAccess direct=cache.addOrReplaceDirect(i,null,i + 10);
      try {
        for (int c=0; c < i + 10; c++)         direct.buffer().put((byte)i);
      }
  finally {
        Assert.assertTrue(direct.commit());
      }
    }
  }
 }