Program: 4056
Project: 4056
Buggy source:
public void testNetworkClass(){
  final int k=KademliaSettings.REPLICATION_PARAMETER.getValue();
  RouteTableSettings.MAX_CACHE_SIZE.setValue(k);
  RouteTableSettings.MAX_CONTACTS_PER_NETWORK_CLASS_RATIO.setValue(1.0f);
  RouteTable routeTable1=new RouteTableImpl();
  for (int i=0; i < (k - 1); i++) {
    Contact node=ContactFactory.createUnknownContact(Vendor.UNKNOWN,Version.ZERO,KUID.createRandomID(),new InetSocketAddress("String_Node_Str" + i,1024 + i));
    routeTable1.add(node);
  }
  assertEquals(k,routeTable1.size());
  assertEquals(k,routeTable1.getActiveContacts().size());
  assertEquals(0,routeTable1.getCachedContacts().size());
  RouteTableSettings.MAX_CONTACTS_PER_NETWORK_CLASS_RATIO.setValue(0.0f);
  RouteTable routeTable2=new RouteTableImpl();
  for (int i=0; i < (k - 1); i++) {
    Contact node=ContactFactory.createUnknownContact(Vendor.UNKNOWN,Version.ZERO,KUID.createRandomID(),new InetSocketAddress("String_Node_Str" + i,1024 + i));
    routeTable2.add(node);
  }
  assertEquals(k,routeTable2.size());
  assertEquals(2,routeTable2.getActiveContacts().size());
  assertEquals(18,routeTable2.getCachedContacts().size());
  RouteTableSettings.MAX_CONTACTS_PER_NETWORK_CLASS_RATIO.setValue(0.5f);
  RouteTable routeTable3=new RouteTableImpl();
  for (int i=0; i < (k - 1); i++) {
    Contact node=ContactFactory.createUnknownContact(Vendor.UNKNOWN,Version.ZERO,KUID.createRandomID(),new InetSocketAddress("String_Node_Str" + i,1024 + i));
    routeTable3.add(node);
  }
  assertEquals(k,routeTable3.size());
  assertEquals(k / 2 + 1,routeTable3.getActiveContacts().size());
  assertEquals(k / 2 - 1,routeTable3.getCachedContacts().size());
  Contact node=ContactFactory.createLiveContact(new InetSocketAddress("String_Node_Str",2000),Vendor.UNKNOWN,Version.ZERO,KUID.createRandomID(),new InetSocketAddress("String_Node_Str",2000),0,Contact.DEFAULT_FLAG);
  routeTable3.add(node);
  assertEquals(k + 1,routeTable3.size());
  assertEquals(k / 2 + 2,routeTable3.getActiveContacts().size());
  assertEquals(k / 2 - 1,routeTable3.getCachedContacts().size());
  Bucket bucket=routeTable3.getBucket(node.getNodeID());
  assertNotNull(bucket);
  ClassfulNetworkCounter counter=bucket.getClassfulNetworkCounter();
  int count=counter.get(node);
  assertEquals(1,count);
  boolean removed=bucket.remove(node.getNodeID());
  assertTrue(removed);
  count=counter.get(node);
  assertEquals(0,count);
}

Fixed version (ground truth):
public void testNetworkClass(){
  final int k=KademliaSettings.REPLICATION_PARAMETER.getValue();
  RouteTableSettings.MAX_CACHE_SIZE.setValue(k);
  RouteTableSettings.MAX_CONTACTS_PER_NETWORK_CLASS_RATIO.setValue(1.0f);
  RouteTable routeTable1=new RouteTableImpl();
  for (int i=0; i < (k - 1); i++) {
    Contact node=ContactFactory.createUnknownContact(Vendor.UNKNOWN,Version.ZERO,KUID.createRandomID(),new InetSocketAddress("String_Node_Str" + i,1024 + i));
    routeTable1.add(node);
  }
  assertEquals(k,routeTable1.size());
  assertEquals(k,routeTable1.getActiveContacts().size());
  assertEquals(0,routeTable1.getCachedContacts().size());
  RouteTableSettings.MAX_CONTACTS_PER_NETWORK_CLASS_RATIO.setValue(0.0f);
  RouteTable routeTable2=new RouteTableImpl();
  for (int i=0; i < (k - 1); i++) {
    Contact node=ContactFactory.createUnknownContact(Vendor.UNKNOWN,Version.ZERO,KUID.createRandomID(),new InetSocketAddress("String_Node_Str" + i,1024 + i));
    routeTable2.add(node);
  }
  assertEquals(2,routeTable2.size());
  assertEquals(2,routeTable2.getActiveContacts().size());
  assertEquals(0,routeTable2.getCachedContacts().size());
  RouteTableSettings.MAX_CONTACTS_PER_NETWORK_CLASS_RATIO.setValue(0.5f);
  RouteTable routeTable3=new RouteTableImpl();
  for (int i=0; i < (k - 1); i++) {
    Contact node=ContactFactory.createUnknownContact(Vendor.UNKNOWN,Version.ZERO,KUID.createRandomID(),new InetSocketAddress("String_Node_Str" + i,1024 + i));
    routeTable3.add(node);
  }
  assertEquals(k / 2 + 1,routeTable3.size());
  assertEquals(k / 2 + 1,routeTable3.getActiveContacts().size());
  assertEquals(0,routeTable3.getCachedContacts().size());
  Contact node=ContactFactory.createLiveContact(new InetSocketAddress("String_Node_Str",2000),Vendor.UNKNOWN,Version.ZERO,KUID.createRandomID(),new InetSocketAddress("String_Node_Str",2000),0,Contact.DEFAULT_FLAG);
  routeTable3.add(node);
  assertEquals(k / 2 + 1 + 1,routeTable3.size());
  assertEquals(k / 2 + 1 + 1,routeTable3.getActiveContacts().size());
  assertEquals(0,routeTable3.getCachedContacts().size());
  Bucket bucket=routeTable3.getBucket(node.getNodeID());
  assertNotNull(bucket);
  ClassfulNetworkCounter counter=bucket.getClassfulNetworkCounter();
  int count=counter.get(node);
  assertEquals(1,count);
  boolean removed=bucket.remove(node.getNodeID());
  assertTrue(removed);
  count=counter.get(node);
  assertEquals(0,count);
}