Program: 116675
Project: 116675
Buggy source:
public void addCluster(int tenantId,String cartridgeType,String subscriptionAlias,Cluster cluster){
  Set<CartridgeTypeContext> cartridgeTypeContextSet=null;
  Set<SubscriptionAliasContext> subscriptionAliasContextSet=null;
  writeLock.lock();
  try {
    cartridgeTypeContextSet=tenantIdToCartridgeTypeContextMap.get(tenantId);
    if (cartridgeTypeContextSet != null) {
      CartridgeTypeContext cartridgeTypeContext=null;
      Iterator<CartridgeTypeContext> typeCtxIterator=cartridgeTypeContextSet.iterator();
      while (typeCtxIterator.hasNext()) {
        cartridgeTypeContext=typeCtxIterator.next();
        if (cartridgeTypeContext.getType().equals(cartridgeType)) {
          subscriptionAliasContextSet=cartridgeTypeContext.getSubscriptionAliasContextSet();
          break;
        }
      }
      if (subscriptionAliasContextSet == null) {
        SubscriptionAliasContext subscriptionAliasContext=new SubscriptionAliasContext(subscriptionAlias,cluster);
        subscriptionAliasContextSet=new HashSet<SubscriptionAliasContext>();
        subscriptionAliasContextSet.add(subscriptionAliasContext);
        cartridgeTypeContext=new CartridgeTypeContext(cartridgeType);
        cartridgeTypeContext.setSubscriptionAliasContextSet(subscriptionAliasContextSet);
        cartridgeTypeContextSet.add(cartridgeTypeContext);
      }
 else {
        subscriptionAliasContextSet.remove(new SubscriptionAliasContext(subscriptionAlias,null));
        subscriptionAliasContextSet.add(new SubscriptionAliasContext(subscriptionAlias,cluster));
      }
    }
 else {
      SubscriptionAliasContext subscriptionAliasContext=new SubscriptionAliasContext(subscriptionAlias,cluster);
      subscriptionAliasContextSet=new HashSet<SubscriptionAliasContext>();
      subscriptionAliasContextSet.add(subscriptionAliasContext);
      CartridgeTypeContext cartridgeTypeContext=new CartridgeTypeContext(cartridgeType);
      cartridgeTypeContext.setSubscriptionAliasContextSet(subscriptionAliasContextSet);
      cartridgeTypeContextSet=new HashSet<CartridgeTypeContext>();
      cartridgeTypeContextSet.add(cartridgeTypeContext);
      tenantIdToCartridgeTypeContextMap.put(tenantId,cartridgeTypeContextSet);
    }
  }
  finally {
    writeLock.unlock();
  }
}

Fixed version (ground truth):
public void addCluster(int tenantId,String cartridgeType,String subscriptionAlias,Cluster cluster){
  Set<CartridgeTypeContext> cartridgeTypeContextSet=null;
  Set<SubscriptionAliasContext> subscriptionAliasContextSet=null;
  writeLock.lock();
  try {
    cartridgeTypeContextSet=tenantIdToCartridgeTypeContextMap.get(tenantId);
    if (cartridgeTypeContextSet != null) {
      CartridgeTypeContext cartridgeTypeContext=null;
      Iterator<CartridgeTypeContext> typeCtxIterator=cartridgeTypeContextSet.iterator();
      while (typeCtxIterator.hasNext()) {
        cartridgeTypeContext=typeCtxIterator.next();
        if (cartridgeTypeContext.getType().equals(cartridgeType)) {
          subscriptionAliasContextSet=cartridgeTypeContext.getSubscriptionAliasContextSet();
          break;
        }
      }
      if (subscriptionAliasContextSet == null) {
        SubscriptionAliasContext subscriptionAliasContext=new SubscriptionAliasContext(subscriptionAlias,cluster);
        subscriptionAliasContextSet=new HashSet<SubscriptionAliasContext>();
        subscriptionAliasContextSet.add(subscriptionAliasContext);
        cartridgeTypeContext=new CartridgeTypeContext(cartridgeType);
        cartridgeTypeContext.setSubscriptionAliasContextSet(subscriptionAliasContextSet);
        cartridgeTypeContextSet.add(cartridgeTypeContext);
        if (log.isDebugEnabled()) {
          log.debug("String_Node_Str" + cluster.toString());
        }
      }
 else {
        subscriptionAliasContextSet.remove(new SubscriptionAliasContext(subscriptionAlias,null));
        subscriptionAliasContextSet.add(new SubscriptionAliasContext(subscriptionAlias,cluster));
        if (log.isDebugEnabled()) {
          log.debug("String_Node_Str" + cluster.toString());
        }
      }
    }
 else {
      SubscriptionAliasContext subscriptionAliasContext=new SubscriptionAliasContext(subscriptionAlias,cluster);
      subscriptionAliasContextSet=new HashSet<SubscriptionAliasContext>();
      subscriptionAliasContextSet.add(subscriptionAliasContext);
      CartridgeTypeContext cartridgeTypeContext=new CartridgeTypeContext(cartridgeType);
      cartridgeTypeContext.setSubscriptionAliasContextSet(subscriptionAliasContextSet);
      cartridgeTypeContextSet=new HashSet<CartridgeTypeContext>();
      cartridgeTypeContextSet.add(cartridgeTypeContext);
      tenantIdToCartridgeTypeContextMap.put(tenantId,cartridgeTypeContextSet);
      if (log.isDebugEnabled()) {
        log.debug("String_Node_Str" + cluster.toString());
      }
    }
  }
  finally {
    writeLock.unlock();
  }
}