Program: 135838
Project: 135838
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) {
    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);
    WriteTransaction writeTransaction=dataService.newWriteOnlyTransaction();
    writeTransaction.merge(LogicalDatastoreType.OPERATIONAL,addressCapableNcInstanceId,acncBuilder.build());
    writeTransaction.submit();
  }
}

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(2,TimeUnit.SECONDS);
      }
 catch (      InterruptedException|ExecutionException|TimeoutException 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);
    WriteTransaction writeTransaction=dataService.newWriteOnlyTransaction();
    writeTransaction.merge(LogicalDatastoreType.OPERATIONAL,addressCapableNcInstanceId,acncBuilder.build());
    futureMap.put(nodeConnectorLock,writeTransaction.submit());
  }
}