Program: 36768
Project: 36768
Buggy source:
public void mapPort(RewriteableMsg msg,Address v,InetAddress destIp,int dstPort,InetAddress srcIp,int srcPort,int rtoRetries){
  int portToMap=0;
switch (allocationPolicy) {
case PORT_PRESERVATION:
    Address mappedEnd=pubPortToPrivateAddr.get(srcPort);
  if (mappedEnd == null && rtoRetries == 0) {
    portToMap=srcPort;
  }
 else {
    if ((clashingOverrides || isExpired(srcPort)) && rtoRetries == 0) {
      portToMap=srcPort;
    }
 else {
switch (alternativePortAllocationPolicy) {
case PORT_CONTIGUITY:
        portToMap=getContiguousPort();
      break;
case RANDOM:
    portToMap=getRandomPort_UnusedIfPossible();
  break;
default :
portToMap=getRandomPort_UnusedIfPossible();
break;
}
}
}
break;
case PORT_CONTIGUITY:
portToMap=getContiguousPort();
break;
case RANDOM:
portToMap=getRandomPort_UnusedIfPossible();
break;
default :
break;
}
logger.trace(compName + "String_Node_Str" + v.getPort()+ "String_Node_Str"+ portToMap);
Address a=new Address(natPublicAddress,portToMap,99);
PortBindRequest req=new PortBindRequest(a,msg.getProtocol());
BindingSession session=new BindingSession(v,destIp,dstPort,msg);
NatPortBindResponse resp=new NatPortBindResponse(req,session,rtoRetries);
req.setResponse(resp);
delegator.doTrigger(req,lowerNetControl);
if (pubPortToPrivateAddr.containsKey(portToMap)) {
logger.warn(compName + "String_Node_Str" + pubPortToPrivateAddr.get(portToMap),portToMap,v);
}
pubPortToPrivateAddr.put(portToMap,v);
Map<InetAddress,Map<Integer,Integer>> map=null;
if (!privateEndPointToDestinationTable.containsKey(v)) {
map=new HashMap<InetAddress,Map<Integer,Integer>>();
privateEndPointToDestinationTable.put(v,map);
}
 else {
map=privateEndPointToDestinationTable.get(v);
}
Map<Integer,Integer> s;
if (map.containsKey(destIp)) {
s=map.get(destIp);
}
 else {
s=new HashMap<Integer,Integer>();
}
s.put(dstPort,portToMap);
map.put(destIp,s);
logger.trace(compName + "String_Node_Str" + portToMap+ "String_Node_Str"+ v+ "String_Node_Str"+ destIp+ "String_Node_Str"+ dstPort);
}

Fixed version (ground truth):
public void mapPort(RewriteableMsg msg,Address v,InetAddress destIp,int dstPort,InetAddress srcIp,int srcPort,int rtoRetries){
  int portToMap=0;
switch (allocationPolicy) {
case PORT_PRESERVATION:
    Address mappedEnd=pubPortToPrivateAddr.get(srcPort);
  if (mappedEnd == null && rtoRetries == 0) {
    portToMap=srcPort;
  }
 else {
    if ((clashingOverrides || isExpired(srcPort)) && rtoRetries == 0) {
      portToMap=srcPort;
    }
 else {
switch (alternativePortAllocationPolicy) {
case PORT_CONTIGUITY:
        portToMap=getContiguousPort();
      break;
case RANDOM:
    portToMap=getRandomPort_UnusedIfPossible();
  break;
default :
portToMap=getRandomPort_UnusedIfPossible();
break;
}
}
}
break;
case PORT_CONTIGUITY:
portToMap=getContiguousPort();
break;
case RANDOM:
portToMap=getRandomPort_UnusedIfPossible();
break;
default :
break;
}
logger.trace(compName + "String_Node_Str" + v.getPort()+ "String_Node_Str"+ portToMap);
Address a=new Address(natPublicAddress,portToMap,99);
PortBindRequest req=new PortBindRequest(a,msg.getProtocol());
BindingSession session=new BindingSession(v,destIp,dstPort,msg);
NatPortBindResponse resp=new NatPortBindResponse(req,session,rtoRetries);
req.setResponse(resp);
trigger(req,lowerNetControl);
if (pubPortToPrivateAddr.containsKey(portToMap)) {
logger.warn(compName + "String_Node_Str" + pubPortToPrivateAddr.get(portToMap),portToMap,v);
}
pubPortToPrivateAddr.put(portToMap,v);
Map<InetAddress,Map<Integer,Integer>> map=null;
if (!privateEndPointToDestinationTable.containsKey(v)) {
map=new HashMap<InetAddress,Map<Integer,Integer>>();
privateEndPointToDestinationTable.put(v,map);
}
 else {
map=privateEndPointToDestinationTable.get(v);
}
Map<Integer,Integer> s;
if (map.containsKey(destIp)) {
s=map.get(destIp);
}
 else {
s=new HashMap<Integer,Integer>();
}
s.put(dstPort,portToMap);
map.put(destIp,s);
logger.trace(compName + "String_Node_Str" + portToMap+ "String_Node_Str"+ v+ "String_Node_Str"+ destIp+ "String_Node_Str"+ dstPort);
}