Program: 159562
Project: 159562
Buggy source:
public void apply(Game game){
  removeInactiveEffects(game);
  List<ContinuousEffect> layerEffects=getLayeredEffects(game);
  List<ContinuousEffect> layer=filterLayeredEffects(layerEffects,Layer.CopyEffects_1);
  for (  ContinuousEffect effect : layer) {
    HashSet<Ability> abilities=layeredEffects.getAbility(effect.getId());
    for (    Ability ability : abilities) {
      effect.apply(Layer.CopyEffects_1,SubLayer.NA,ability,game);
    }
  }
  if (layer.size() > 0) {
    layerEffects=getLayeredEffects(game);
  }
  layer=filterLayeredEffects(layerEffects,Layer.ControlChangingEffects_2);
  for (  ContinuousEffect effect : layer) {
    HashSet<Ability> abilities=layeredEffects.getAbility(effect.getId());
    for (    Ability ability : abilities) {
      effect.apply(Layer.ControlChangingEffects_2,SubLayer.NA,ability,game);
    }
  }
  layer=filterLayeredEffects(layerEffects,Layer.TextChangingEffects_3);
  for (  ContinuousEffect effect : layer) {
    HashSet<Ability> abilities=layeredEffects.getAbility(effect.getId());
    for (    Ability ability : abilities) {
      effect.apply(Layer.TextChangingEffects_3,SubLayer.NA,ability,game);
    }
  }
  layer=filterLayeredEffects(layerEffects,Layer.TypeChangingEffects_4);
  for (  ContinuousEffect effect : layer) {
    HashSet<Ability> abilities=layeredEffects.getAbility(effect.getId());
    for (    Ability ability : abilities) {
      effect.apply(Layer.TypeChangingEffects_4,SubLayer.NA,ability,game);
    }
  }
  layer=filterLayeredEffects(layerEffects,Layer.ColorChangingEffects_5);
  for (  ContinuousEffect effect : layer) {
    HashSet<Ability> abilities=layeredEffects.getAbility(effect.getId());
    for (    Ability ability : abilities) {
      effect.apply(Layer.ColorChangingEffects_5,SubLayer.NA,ability,game);
    }
  }
  layer=filterLayeredEffects(layerEffects,Layer.AbilityAddingRemovingEffects_6);
  for (  ContinuousEffect effect : layer) {
    if (layerEffects.contains(effect)) {
      HashSet<Ability> abilities=layeredEffects.getAbility(effect.getId());
      for (      Ability ability : abilities) {
        effect.apply(Layer.AbilityAddingRemovingEffects_6,SubLayer.NA,ability,game);
      }
    }
    layerEffects=getLayeredEffects(game);
  }
  layer=filterLayeredEffects(layerEffects,Layer.PTChangingEffects_7);
  for (  ContinuousEffect effect : layer) {
    HashSet<Ability> abilities=layeredEffects.getAbility(effect.getId());
    for (    Ability ability : abilities) {
      effect.apply(Layer.PTChangingEffects_7,SubLayer.SetPT_7b,ability,game);
    }
  }
  for (  ContinuousEffect effect : layer) {
    HashSet<Ability> abilities=layeredEffects.getAbility(effect.getId());
    for (    Ability ability : abilities) {
      effect.apply(Layer.PTChangingEffects_7,SubLayer.ModifyPT_7c,ability,game);
    }
  }
  applyCounters.apply(Layer.PTChangingEffects_7,SubLayer.Counters_7d,null,game);
  for (  ContinuousEffect effect : layer) {
    HashSet<Ability> abilities=layeredEffects.getAbility(effect.getId());
    for (    Ability ability : abilities) {
      effect.apply(Layer.PTChangingEffects_7,SubLayer.SwitchPT_e,ability,game);
    }
  }
  layer=filterLayeredEffects(layerEffects,Layer.PlayerEffects);
  for (  ContinuousEffect effect : layer) {
    HashSet<Ability> abilities=layeredEffects.getAbility(effect.getId());
    for (    Ability ability : abilities) {
      effect.apply(Layer.PlayerEffects,SubLayer.NA,ability,game);
    }
  }
  layer=filterLayeredEffects(layerEffects,Layer.RulesEffects);
  for (  ContinuousEffect effect : layer) {
    HashSet<Ability> abilities=layeredEffects.getAbility(effect.getId());
    for (    Ability ability : abilities) {
      effect.apply(Layer.RulesEffects,SubLayer.NA,ability,game);
    }
  }
}

Fixed version (ground truth):
public void apply(Game game){
  removeInactiveEffects(game);
  List<ContinuousEffect> layerEffects=getLayeredEffects(game);
  List<ContinuousEffect> layer=filterLayeredEffects(layerEffects,Layer.CopyEffects_1);
  for (  ContinuousEffect effect : layer) {
    HashSet<Ability> abilities=layeredEffects.getAbility(effect.getId());
    for (    Ability ability : abilities) {
      effect.apply(Layer.CopyEffects_1,SubLayer.NA,ability,game);
    }
  }
  if (layer.size() > 0) {
    layerEffects=getLayeredEffects(game);
  }
  layer=filterLayeredEffects(layerEffects,Layer.ControlChangingEffects_2);
  for (  ContinuousEffect effect : layer) {
    HashSet<Ability> abilities=layeredEffects.getAbility(effect.getId());
    for (    Ability ability : abilities) {
      effect.apply(Layer.ControlChangingEffects_2,SubLayer.NA,ability,game);
    }
  }
  layer=filterLayeredEffects(layerEffects,Layer.TextChangingEffects_3);
  for (  ContinuousEffect effect : layer) {
    HashSet<Ability> abilities=layeredEffects.getAbility(effect.getId());
    for (    Ability ability : abilities) {
      effect.apply(Layer.TextChangingEffects_3,SubLayer.NA,ability,game);
    }
  }
  layer=filterLayeredEffects(layerEffects,Layer.TypeChangingEffects_4);
  for (  ContinuousEffect effect : layer) {
    HashSet<Ability> abilities=layeredEffects.getAbility(effect.getId());
    for (    Ability ability : abilities) {
      effect.apply(Layer.TypeChangingEffects_4,SubLayer.NA,ability,game);
    }
  }
  layer=filterLayeredEffects(layerEffects,Layer.ColorChangingEffects_5);
  for (  ContinuousEffect effect : layer) {
    HashSet<Ability> abilities=layeredEffects.getAbility(effect.getId());
    for (    Ability ability : abilities) {
      effect.apply(Layer.ColorChangingEffects_5,SubLayer.NA,ability,game);
    }
  }
  Map<ContinuousEffect,List<Ability>> appliedEffects=new HashMap<ContinuousEffect,List<Ability>>();
  boolean allApplied=false;
  while (!allApplied) {
    boolean effectApplied=false;
    layer=filterLayeredEffects(layerEffects,Layer.AbilityAddingRemovingEffects_6);
    for (    ContinuousEffect effect : layer) {
      if (layerEffects.contains(effect)) {
        List<Ability> appliedAbilities=appliedEffects.get(effect);
        HashSet<Ability> abilities=layeredEffects.getAbility(effect.getId());
        for (        Ability ability : abilities) {
          if (appliedAbilities == null || !appliedAbilities.contains(ability)) {
            if (appliedAbilities == null) {
              appliedAbilities=new ArrayList<Ability>();
              appliedEffects.put(effect,appliedAbilities);
            }
            appliedAbilities.add(ability);
            effect.apply(Layer.AbilityAddingRemovingEffects_6,SubLayer.NA,ability,game);
            effectApplied=true;
          }
        }
      }
    }
    allApplied=!effectApplied;
    if (effectApplied) {
      layerEffects=getLayeredEffects(game);
    }
  }
  layer=filterLayeredEffects(layerEffects,Layer.PTChangingEffects_7);
  for (  ContinuousEffect effect : layer) {
    HashSet<Ability> abilities=layeredEffects.getAbility(effect.getId());
    for (    Ability ability : abilities) {
      effect.apply(Layer.PTChangingEffects_7,SubLayer.SetPT_7b,ability,game);
    }
  }
  for (  ContinuousEffect effect : layer) {
    HashSet<Ability> abilities=layeredEffects.getAbility(effect.getId());
    for (    Ability ability : abilities) {
      effect.apply(Layer.PTChangingEffects_7,SubLayer.ModifyPT_7c,ability,game);
    }
  }
  applyCounters.apply(Layer.PTChangingEffects_7,SubLayer.Counters_7d,null,game);
  for (  ContinuousEffect effect : layer) {
    HashSet<Ability> abilities=layeredEffects.getAbility(effect.getId());
    for (    Ability ability : abilities) {
      effect.apply(Layer.PTChangingEffects_7,SubLayer.SwitchPT_e,ability,game);
    }
  }
  layer=filterLayeredEffects(layerEffects,Layer.PlayerEffects);
  for (  ContinuousEffect effect : layer) {
    HashSet<Ability> abilities=layeredEffects.getAbility(effect.getId());
    for (    Ability ability : abilities) {
      effect.apply(Layer.PlayerEffects,SubLayer.NA,ability,game);
    }
  }
  layer=filterLayeredEffects(layerEffects,Layer.RulesEffects);
  for (  ContinuousEffect effect : layer) {
    HashSet<Ability> abilities=layeredEffects.getAbility(effect.getId());
    for (    Ability ability : abilities) {
      effect.apply(Layer.RulesEffects,SubLayer.NA,ability,game);
    }
  }
}