Program: 16443
Project: 16443
Buggy source:
/** 
 * Given all chains of all models find entities for the nonpolymers and water chains within them, assigning entity ids, types and descriptions to them. The result is written back to the passed entities List.
 * @param nonPolyModels
 * @param waterModels
 * @param entities
 */
public static void createPurelyNonPolyEntities(List<List<Chain>> nonPolyModels,List<List<Chain>> waterModels,List<EntityInfo> entities){
  int maxMolId=0;
  if (!entities.isEmpty()) {
    maxMolId=Collections.max(entities,new Comparator<EntityInfo>(){
      @Override public int compare(      EntityInfo o1,      EntityInfo o2){
        return new Integer(o1.getMolId()).compareTo(o2.getMolId());
      }
    }
).getMolId();
  }
  int molId=maxMolId + 1;
  if (!nonPolyModels.get(0).isEmpty()) {
    List<EntityInfo> nonPolyEntities=new ArrayList<>();
    for (    List<Chain> model : nonPolyModels) {
      for (      Chain c : model) {
        String molecPdbName=c.getAtomGroup(0).getPDBName();
        EntityInfo nonPolyEntity=findNonPolyEntityWithDescription(molecPdbName,nonPolyEntities);
        if (nonPolyEntity == null) {
          nonPolyEntity=new EntityInfo();
          nonPolyEntity.setDescription(molecPdbName);
          nonPolyEntity.setType(EntityType.NONPOLYMER);
          nonPolyEntity.setMolId(molId++);
          nonPolyEntities.add(nonPolyEntity);
        }
        nonPolyEntity.addChain(c);
        c.setEntityInfo(nonPolyEntity);
      }
    }
    entities.addAll(nonPolyEntities);
  }
  if (!waterModels.get(0).isEmpty()) {
    EntityInfo waterEntity=new EntityInfo();
    waterEntity.setType(EntityType.WATER);
    waterEntity.setDescription("String_Node_Str");
    waterEntity.setMolId(molId);
    for (    List<Chain> model : waterModels) {
      for (      Chain waterChain : model) {
        waterEntity.addChain(waterChain);
        waterChain.setEntityInfo(waterEntity);
      }
    }
    entities.add(waterEntity);
  }
}

Fixed version (ground truth):
/** 
 * Given all chains of all models find entities for the nonpolymers and water chains within them, assigning entity ids, types and descriptions to them. The result is written back to the passed entities List.
 * @param nonPolyModels
 * @param waterModels
 * @param entities
 */
public static void createPurelyNonPolyEntities(List<List<Chain>> nonPolyModels,List<List<Chain>> waterModels,List<EntityInfo> entities){
  if (nonPolyModels.isEmpty())   return;
  int maxMolId=0;
  if (!entities.isEmpty()) {
    maxMolId=Collections.max(entities,new Comparator<EntityInfo>(){
      @Override public int compare(      EntityInfo o1,      EntityInfo o2){
        return new Integer(o1.getMolId()).compareTo(o2.getMolId());
      }
    }
).getMolId();
  }
  int molId=maxMolId + 1;
  if (!nonPolyModels.get(0).isEmpty()) {
    List<EntityInfo> nonPolyEntities=new ArrayList<>();
    for (    List<Chain> model : nonPolyModels) {
      for (      Chain c : model) {
        String molecPdbName=c.getAtomGroup(0).getPDBName();
        EntityInfo nonPolyEntity=findNonPolyEntityWithDescription(molecPdbName,nonPolyEntities);
        if (nonPolyEntity == null) {
          nonPolyEntity=new EntityInfo();
          nonPolyEntity.setDescription(molecPdbName);
          nonPolyEntity.setType(EntityType.NONPOLYMER);
          nonPolyEntity.setMolId(molId++);
          nonPolyEntities.add(nonPolyEntity);
        }
        nonPolyEntity.addChain(c);
        c.setEntityInfo(nonPolyEntity);
      }
    }
    entities.addAll(nonPolyEntities);
  }
  if (!waterModels.get(0).isEmpty()) {
    EntityInfo waterEntity=new EntityInfo();
    waterEntity.setType(EntityType.WATER);
    waterEntity.setDescription("String_Node_Str");
    waterEntity.setMolId(molId);
    for (    List<Chain> model : waterModels) {
      for (      Chain waterChain : model) {
        waterEntity.addChain(waterChain);
        waterChain.setEntityInfo(waterEntity);
      }
    }
    entities.add(waterEntity);
  }
}