Program: 116681
Project: 116681
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>();
      cartridgeTypeContext.setSubscriptionAliasContextSet(subscriptionAliasContextSet);
      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);
      }
 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();
  }
}