Program: 152593
Project: 152593
Buggy source:
private static int calcDefenseOrSpecialDefense(BattlePlayer playerDefender,BattlePlayer playerAttacker,Move move,Battle stats){
  Pokemon defender=playerDefender.getPokemon();
  Pokemon attacker=playerAttacker.getPokemon();
  int defense=1;
  int stat=1;
  double sm=1;
  double mod=1;
switch (move.getKind()) {
case PHYSICAL:
    stat=defender.getStat(Stats.DEFENSE);
  if (defender.getStatStageChange(ModdableBattleStats.DEFENSE) > 0) {
    sm=(defender.getStatStageChange(ModdableBattleStats.DEFENSE) + 2) / 2;
  }
 else   if (defender.getStatStageChange(ModdableBattleStats.DEFENSE) < 0) {
    sm=2 / (defender.getStatStageChange(ModdableBattleStats.DEFENSE) + 2);
  }
if (attacker.getAbility() == Ability.UNAWARE && defender.getStatStageChange(ModdableBattleStats.DEFENSE) > 0) {
  sm=1;
}
if (defender.getAbility() == Ability.FLOWER_GIFT && stats.getWeather() == Weather.SUNNY_DAY) {
mod=1.5;
}
switch (defender.getHeldItem()) {
case Items.METAL_POWDER:
if (defender.getSpecies().getDexNumber() == 132) {
mod=(mod * 1.5);
}
break;
case Items.MARVEL_SCALE:
if (defender.isAffectedByStatusAilment()) {
mod=(mod * 1.5);
}
break;
}
break;
case SPECIAL:
stat=defender.getStat(Stats.SPECIAL_DEFENSE);
if (defender.getStatStageChange(ModdableBattleStats.SPECIAL_DEFENSE) > 0) {
sm=(defender.getStatStageChange(ModdableBattleStats.SPECIAL_DEFENSE) + 2) / 2;
}
 else if (defender.getStatStageChange(ModdableBattleStats.SPECIAL_DEFENSE) < 0) {
sm=2 / (defender.getStatStageChange(ModdableBattleStats.SPECIAL_DEFENSE) + 2);
}
if (attacker.getAbility() == Ability.UNAWARE && defender.getStatStageChange(ModdableBattleStats.SPECIAL_DEFENSE) > 0) {
sm=1;
}
if (defender.getAbility() == Ability.FLOWER_GIFT && stats.getWeather() == Weather.SUNNY_DAY) {
mod=1.5;
}
switch (defender.getHeldItem()) {
case Items.METAL_POWDER:
if (defender.getSpecies().getDexNumber() == 132) {
mod=(mod * 1.5);
}
break;
case Items.SOUL_DEW:
if (defender.getSpecies().getDexNumber() == 380 || defender.getSpecies().getDexNumber() == 381) {
mod=(mod * 1.5);
}
break;
case Items.DEEPSEASCALE:
if (defender.getSpecies().getDexNumber() == 366) {
mod=(mod * 1.5);
}
break;
}
if (stats.getWeather() == Weather.SANDSTORM && (defender.getType(1) == Types.ROCK || defender.getType(2) == Types.ROCK)) {
mod=(mod * 1.5);
}
}
defense=(int)(stat * sm * mod);
return defense;
}

Fixed version (ground truth):
private static int calcDefenseOrSpecialDefense(BattlePlayer playerDefender,BattlePlayer playerAttacker,Move move,Battle stats){
  Pokemon defender=playerDefender.getPokemon();
  Pokemon attacker=playerAttacker.getPokemon();
  int defense=1;
  int stat=1;
  double sm=1;
  double mod=1;
switch (move.getKind()) {
case PHYSICAL:
    stat=defender.getStat(Stats.DEFENSE);
  if (defender.getStatStageChange(ModdableBattleStats.DEFENSE) > 0) {
    sm=(defender.getStatStageChange(ModdableBattleStats.DEFENSE) + 2) / 2;
  }
 else   if (defender.getStatStageChange(ModdableBattleStats.DEFENSE) < 0) {
    sm=2 / (defender.getStatStageChange(ModdableBattleStats.DEFENSE) + 2);
  }
if (attacker.hasAbility(Ability.UNAWARE) && defender.getStatStageChange(ModdableBattleStats.DEFENSE) > 0) {
  sm=1;
}
if (defender.hasAbility(Ability.FLOWER_GIFT) && stats.getWeather() == Weather.SUNNY_DAY) {
mod=1.5;
}
switch (defender.getHeldItem()) {
case Items.METAL_POWDER:
if (defender.getSpecies().getDexNumber() == 132) {
mod=(mod * 1.5);
}
break;
case Items.MARVEL_SCALE:
if (defender.isAffectedByStatusAilment()) {
mod=(mod * 1.5);
}
break;
}
break;
case SPECIAL:
stat=defender.getStat(Stats.SPECIAL_DEFENSE);
if (defender.getStatStageChange(ModdableBattleStats.SPECIAL_DEFENSE) > 0) {
sm=(defender.getStatStageChange(ModdableBattleStats.SPECIAL_DEFENSE) + 2) / 2;
}
 else if (defender.getStatStageChange(ModdableBattleStats.SPECIAL_DEFENSE) < 0) {
sm=2 / (defender.getStatStageChange(ModdableBattleStats.SPECIAL_DEFENSE) + 2);
}
if (attacker.hasAbility(Ability.UNAWARE) && defender.getStatStageChange(ModdableBattleStats.SPECIAL_DEFENSE) > 0) {
sm=1;
}
if (defender.hasAbility(Ability.FLOWER_GIFT) && stats.getWeather() == Weather.SUNNY_DAY) {
mod=1.5;
}
switch (defender.getHeldItem()) {
case Items.METAL_POWDER:
if (defender.getSpecies().getDexNumber() == 132) {
mod=(mod * 1.5);
}
break;
case Items.SOUL_DEW:
if (defender.getSpecies().getDexNumber() == 380 || defender.getSpecies().getDexNumber() == 381) {
mod=(mod * 1.5);
}
break;
case Items.DEEPSEASCALE:
if (defender.getSpecies().getDexNumber() == 366) {
mod=(mod * 1.5);
}
break;
}
if (stats.getWeather() == Weather.SANDSTORM && (defender.getType(1) == Types.ROCK || defender.getType(2) == Types.ROCK)) {
mod=(mod * 1.5);
}
}
defense=(int)(stat * sm * mod);
return defense;
}