Program: 135814
Project: 135814
Buggy source:
/** 
 * Add addresses into the MD-SAL data tree
 * @param macAddress       The MacAddress of the new L2Address object
 * @param nodeConnectorRef The NodeConnectorRef of the new L2Address object
 */
public void addAddress(MacAddress macAddress,IpAddress ipAddress,NodeConnectorRef nodeConnectorRef){
  if (macAddress == null || ipAddress == null || nodeConnectorRef == null) {
    return;
  }
  NodeConnectorLock nodeConnectorLock;
synchronized (this) {
    nodeConnectorLock=lockMap.get(nodeConnectorRef);
    if (nodeConnectorLock == null) {
      nodeConnectorLock=new NodeConnectorLock();
      lockMap.put(nodeConnectorRef,nodeConnectorLock);
    }
  }
synchronized (nodeConnectorLock) {
    CheckedFuture<Void,TransactionCommitFailedException> future=futureMap.get(nodeConnectorLock);
    if (future != null) {
      try {
        future.get();
      }
 catch (      InterruptedException|ExecutionException e) {
        _logger.error("String_Node_Str",e);
      }
    }
    long now=new Date().getTime();
    final AddressCapableNodeConnectorBuilder acncBuilder=new AddressCapableNodeConnectorBuilder();
    final AddressesBuilder addressBuilder=new AddressesBuilder().setIp(ipAddress).setMac(macAddress).setFirstSeen(now).setLastSeen(now);
    List<Addresses> addresses=null;
    ReadOnlyTransaction readTransaction=dataService.newReadOnlyTransaction();
    NodeConnector nc=null;
    try {
      Optional<NodeConnector> dataObjectOptional=readTransaction.read(LogicalDatastoreType.OPERATIONAL,(InstanceIdentifier<NodeConnector>)nodeConnectorRef.getValue()).get();
      if (dataObjectOptional.isPresent())       nc=(NodeConnector)dataObjectOptional.get();
    }
 catch (    Exception e) {
      _logger.error("String_Node_Str",nodeConnectorRef.getValue());
      readTransaction.close();
      throw new RuntimeException("String_Node_Str" + nodeConnectorRef,e);
    }
    readTransaction.close();
    if (nc == null) {
      return;
    }
    AddressCapableNodeConnector acnc=(AddressCapableNodeConnector)nc.getAugmentation(AddressCapableNodeConnector.class);
    if (acnc != null && acnc.getAddresses() != null) {
      addresses=acnc.getAddresses();
      for (int i=0; i < addresses.size(); i++) {
        if (addresses.get(i).getIp().equals(ipAddress) && addresses.get(i).getMac().equals(macAddress)) {
          if ((now - addresses.get(i).getLastSeen()) > timestampUpdateInterval) {
            addressBuilder.setFirstSeen(addresses.get(i).getFirstSeen()).setKey(addresses.get(i).getKey());
            addresses.remove(i);
            break;
          }
 else {
            return;
          }
        }
      }
    }
 else {
      addresses=new ArrayList<>();
    }
    if (addressBuilder.getKey() == null) {
      addressBuilder.setKey(new AddressesKey(BigInteger.valueOf(addressKey.getAndIncrement())));
    }
    addresses.add(addressBuilder.build());
    acncBuilder.setAddresses(addresses);
    InstanceIdentifier<AddressCapableNodeConnector> addressCapableNcInstanceId=((InstanceIdentifier<NodeConnector>)nodeConnectorRef.getValue()).augmentation(AddressCapableNodeConnector.class);
    final WriteTransaction writeTransaction=dataService.newWriteOnlyTransaction();
    writeTransaction.merge(LogicalDatastoreType.OPERATIONAL,addressCapableNcInstanceId,acncBuilder.build());
    final CheckedFuture writeTxResultFuture=writeTransaction.submit();
    Futures.addCallback(writeTxResultFuture,new FutureCallback(){
      @Override public void onSuccess(      Object o){
        _logger.debug("String_Node_Str",writeTransaction.getIdentifier());
      }
      @Override public void onFailure(      Throwable throwable){
        _logger.error("String_Node_Str",writeTransaction.getIdentifier(),throwable.getCause());
      }
    }
);
    futureMap.put(nodeConnectorLock,writeTxResultFuture);
  }
}

Fixed version (ground truth):
/** 
 * Add addresses into the MD-SAL data tree
 * @param macAddress The MacAddress of the new L2Address object
 * @param nodeConnectorRef The NodeConnectorRef of the new L2Address object
 */
public void addAddress(MacAddress macAddress,IpAddress ipAddress,NodeConnectorRef nodeConnectorRef){
  if (macAddress == null || ipAddress == null || nodeConnectorRef == null) {
    return;
  }
  NodeConnectorLock nodeConnectorLock;
synchronized (this) {
    nodeConnectorLock=lockMap.get(nodeConnectorRef);
    if (nodeConnectorLock == null) {
      nodeConnectorLock=new NodeConnectorLock();
      lockMap.put(nodeConnectorRef,nodeConnectorLock);
    }
  }
synchronized (nodeConnectorLock) {
    CheckedFuture<Void,TransactionCommitFailedException> future=futureMap.get(nodeConnectorLock);
    if (future != null) {
      try {
        future.get();
      }
 catch (      InterruptedException|ExecutionException e) {
        LOG.error("String_Node_Str",e);
      }
    }
    long now=new Date().getTime();
    final AddressCapableNodeConnectorBuilder acncBuilder=new AddressCapableNodeConnectorBuilder();
    final AddressesBuilder addressBuilder=new AddressesBuilder().setIp(ipAddress).setMac(macAddress).setFirstSeen(now).setLastSeen(now);
    List<Addresses> addresses=null;
    ReadOnlyTransaction readTransaction=dataService.newReadOnlyTransaction();
    NodeConnector nc=null;
    try {
      Optional<NodeConnector> dataObjectOptional=readTransaction.read(LogicalDatastoreType.OPERATIONAL,(InstanceIdentifier<NodeConnector>)nodeConnectorRef.getValue()).get();
      if (dataObjectOptional.isPresent())       nc=(NodeConnector)dataObjectOptional.get();
    }
 catch (    Exception e) {
      LOG.error("String_Node_Str",nodeConnectorRef.getValue());
      readTransaction.close();
      throw new RuntimeException("String_Node_Str" + nodeConnectorRef,e);
    }
    readTransaction.close();
    if (nc == null) {
      return;
    }
    AddressCapableNodeConnector acnc=(AddressCapableNodeConnector)nc.getAugmentation(AddressCapableNodeConnector.class);
    if (acnc != null && acnc.getAddresses() != null) {
      addresses=acnc.getAddresses();
      for (int i=0; i < addresses.size(); i++) {
        if (addresses.get(i).getIp().equals(ipAddress) && addresses.get(i).getMac().equals(macAddress)) {
          if ((now - addresses.get(i).getLastSeen()) > timestampUpdateInterval) {
            addressBuilder.setFirstSeen(addresses.get(i).getFirstSeen()).setKey(addresses.get(i).getKey());
            addresses.remove(i);
            break;
          }
 else {
            return;
          }
        }
      }
    }
 else {
      addresses=new ArrayList<>();
    }
    if (addressBuilder.getKey() == null) {
      addressBuilder.setKey(new AddressesKey(BigInteger.valueOf(addressKey.getAndIncrement())));
    }
    addresses.add(addressBuilder.build());
    acncBuilder.setAddresses(addresses);
    InstanceIdentifier<AddressCapableNodeConnector> addressCapableNcInstanceId=((InstanceIdentifier<NodeConnector>)nodeConnectorRef.getValue()).augmentation(AddressCapableNodeConnector.class);
    final WriteTransaction writeTransaction=dataService.newWriteOnlyTransaction();
    writeTransaction.merge(LogicalDatastoreType.OPERATIONAL,addressCapableNcInstanceId,acncBuilder.build());
    final CheckedFuture writeTxResultFuture=writeTransaction.submit();
    Futures.addCallback(writeTxResultFuture,new FutureCallback(){
      @Override public void onSuccess(      Object o){
        LOG.debug("String_Node_Str",writeTransaction.getIdentifier());
      }
      @Override public void onFailure(      Throwable throwable){
        LOG.error("String_Node_Str",writeTransaction.getIdentifier(),throwable.getCause());
      }
    }
);
    futureMap.put(nodeConnectorLock,writeTxResultFuture);
  }
}