Program: 132423
Project: 132423
Buggy source:
public void testOverlayBufferTree(){
  MultiOverlayBufferTree tree=new MultiOverlayBufferTree(new byte[0],new DefaultByteRangeComparator());
  final int numElements=200;
  final SortedMap<String,byte[]> map1=new TreeMap<String,byte[]>();
  for (int i=0; i < numElements; i++) {
    String keyString=Integer.toHexString(i);
    String valString=Integer.toHexString((int)(Math.random() * Integer.MAX_VALUE));
    byte[] key=keyString.getBytes();
    byte[] val=valString.getBytes();
    map1.put(keyString,val);
    tree.insert(key,val);
  }
  for (int i=0; i < numElements; i++) {
    String keyString=Integer.toHexString(i);
    byte[] key=keyString.getBytes();
    assertEquals(tree.lookup(key),map1.get(keyString));
  }
  int snap1=tree.newOverlay();
  final SortedMap<String,byte[]> map2=new TreeMap<String,byte[]>(map1);
  for (int i=0; i < numElements; i+=2) {
    String keyString=Integer.toHexString(i);
    byte[] key=keyString.getBytes();
    tree.insert(key,null);
    map2.remove(keyString);
  }
  for (int i=0; i < numElements; i++) {
    String keyString=Integer.toHexString(i);
    byte[] key=keyString.getBytes();
    assertEquals(tree.lookup(key),map2.get(keyString));
  }
  int snap2=tree.newOverlay();
  final SortedMap<String,byte[]> map3=new TreeMap<String,byte[]>(map2);
  for (int i=0; i < numElements; i+=5) {
    String keyString=Integer.toHexString(i);
    byte[] key=keyString.getBytes();
    byte[] val=Integer.toHexString((int)(Math.random() * Integer.MAX_VALUE)).getBytes();
    tree.insert(key,val);
    map3.put(keyString,val);
  }
  for (int i=0; i < numElements; i++) {
    String keyString=Integer.toHexString(i);
    byte[] key=keyString.getBytes();
    assertEquals(tree.lookup(key),map3.get(keyString));
  }
  Iterator<Entry<byte[],byte[]>> it=tree.prefixLookup(null,false);
  Iterator<byte[]> itExpected=map3.values().iterator();
  while (it.hasNext())   assertEquals(itExpected.next(),it.next().getValue());
  assertFalse(itExpected.hasNext());
  it=tree.prefixLookup(null,snap1,false);
  itExpected=map1.values().iterator();
  while (it.hasNext())   assertEquals(itExpected.next(),it.next().getValue());
  assertFalse(itExpected.hasNext());
  it=tree.prefixLookup(null,snap2,false);
  itExpected=map2.values().iterator();
  while (it.hasNext())   assertEquals(itExpected.next(),it.next().getValue());
  assertFalse(itExpected.hasNext());
  it=tree.prefixLookup("String_Node_Str".getBytes(),false);
  itExpected=map3.subMap("String_Node_Str","String_Node_Str").values().iterator();
  while (it.hasNext())   assertEquals(itExpected.next(),it.next().getValue());
  assertFalse(itExpected.hasNext());
}

Fixed version (ground truth):
public void testOverlayBufferTree(){
  MultiOverlayBufferTree tree=new MultiOverlayBufferTree(new byte[0],new DefaultByteRangeComparator());
  final int numElements=200;
  final SortedMap<String,byte[]> map1=new TreeMap<String,byte[]>();
  for (int i=0; i < numElements; i++) {
    String keyString=Integer.toHexString(i);
    String valString=Integer.toHexString((int)(Math.random() * Integer.MAX_VALUE));
    byte[] key=keyString.getBytes();
    byte[] val=valString.getBytes();
    map1.put(keyString,val);
    tree.insert(key,val);
  }
  for (int i=0; i < numElements; i++) {
    String keyString=Integer.toHexString(i);
    byte[] key=keyString.getBytes();
    assertEquals(tree.lookup(key),map1.get(keyString));
  }
  int snap1=tree.newOverlay();
  final SortedMap<String,byte[]> map2=new TreeMap<String,byte[]>(map1);
  for (int i=0; i < numElements; i+=2) {
    String keyString=Integer.toHexString(i);
    byte[] key=keyString.getBytes();
    tree.insert(key,null);
    map2.remove(keyString);
  }
  for (int i=0; i < numElements; i++) {
    String keyString=Integer.toHexString(i);
    byte[] key=keyString.getBytes();
    byte[] mapVal=map2.get(keyString);
    byte[] val=tree.lookup(key);
    if (mapVal != null)     assertEquals(mapVal,val);
 else     assertTrue(val == null || val.length == 0);
  }
  int snap2=tree.newOverlay();
  final SortedMap<String,byte[]> map3=new TreeMap<String,byte[]>(map2);
  for (int i=0; i < numElements; i+=5) {
    String keyString=Integer.toHexString(i);
    byte[] key=keyString.getBytes();
    byte[] val=Integer.toHexString((int)(Math.random() * Integer.MAX_VALUE)).getBytes();
    tree.insert(key,val);
    map3.put(keyString,val);
  }
  for (int i=0; i < numElements; i++) {
    String keyString=Integer.toHexString(i);
    byte[] key=keyString.getBytes();
    byte[] mapVal=map3.get(keyString);
    byte[] val=tree.lookup(key);
    if (mapVal != null)     assertEquals(mapVal,val);
 else     assertTrue(val == null || val.length == 0);
  }
  Iterator<Entry<byte[],byte[]>> it=tree.prefixLookup(null,false);
  Iterator<byte[]> itExpected=map3.values().iterator();
  while (it.hasNext())   assertEquals(itExpected.next(),it.next().getValue());
  assertFalse(itExpected.hasNext());
  it=tree.prefixLookup(null,snap1,false);
  itExpected=map1.values().iterator();
  while (it.hasNext())   assertEquals(itExpected.next(),it.next().getValue());
  assertFalse(itExpected.hasNext());
  it=tree.prefixLookup(null,snap2,false);
  itExpected=map2.values().iterator();
  while (it.hasNext())   assertEquals(itExpected.next(),it.next().getValue());
  assertFalse(itExpected.hasNext());
  it=tree.prefixLookup("String_Node_Str".getBytes(),false);
  itExpected=map3.subMap("String_Node_Str","String_Node_Str").values().iterator();
  while (it.hasNext())   assertEquals(itExpected.next(),it.next().getValue());
  assertFalse(itExpected.hasNext());
}