Program: 39451
Project: 39451
Buggy source:
public int doCustomSpawning(WorldServer worldServerIn){
  this.chunksForSpawning.clear();
  int chunkCount=0;
  int successCount=0;
  for (  EntityPlayer entityplayer : worldServerIn.playerEntities) {
    if (!entityplayer.isSpectator()) {
      int playerX=MathHelper.floor(entityplayer.posX / 16.0D);
      int playerY=MathHelper.floor(entityplayer.posZ / 16.0D);
      final int center=8;
      for (int x=-center; x <= center; ++x) {
        for (int z=-center; z <= center; ++z) {
          boolean border=x == -center || x == center || z == -center || z == center;
          ChunkPos chunkpos=new ChunkPos(x + playerX,z + playerY);
          if (!this.chunksForSpawning.contains(chunkpos)) {
            ++chunkCount;
            if (!border && worldServerIn.getWorldBorder().contains(chunkpos)) {
              PlayerChunkMapEntry entry=worldServerIn.getPlayerChunkMap().getEntry(chunkpos.x,chunkpos.z);
              if (entry != null && entry.isSentToPlayers()) {
                this.chunksForSpawning.add(chunkpos);
              }
            }
          }
        }
      }
    }
  }
  for (  PrimitiveMobsSpawnEntry entry : PrimitiveMobsSpawnList.getSpawnEntries()) {
    int entityCount=worldServerIn.countEntities(entry.entityClass);
    int max=Math.round((float)chunkCount * entry.rarity * 0.1F);
    if (entityCount <= max) {
      List<ChunkPos> shuffled=Lists.newArrayList(this.chunksForSpawning);
      Collections.shuffle(shuffled);
      for (      ChunkPos chunk : shuffled) {
        BlockPos pos=getRandomChunkPosition(worldServerIn,chunk.x,chunk.z);
        int x=pos.getX();
        int y=pos.getY();
        int z=pos.getZ();
        IBlockState state=worldServerIn.getBlockState(pos);
        float x1=(float)x + 0.5F;
        float z1=(float)z + 0.5F;
        if (!state.isNormalCube() && !worldServerIn.isAnyPlayerWithinRangeAt((double)x1,(double)y,(double)z1,24.0D)) {
          Biome biome=worldServerIn.getBiome(pos);
          if (!entry.isBiomeSuitable(biome)) {
            continue;
          }
          if (WorldEntitySpawner.canCreatureTypeSpawnAtLocation(EntitySpawnPlacementRegistry.getPlacementForEntity(entry.entityClass),worldServerIn,pos)) {
            EntityLiving entity;
            try {
              entity=(EntityLiving)entry.entityClass.getConstructor(new Class[]{World.class}).newInstance(new Object[]{worldServerIn});
            }
 catch (            Exception exception) {
              exception.printStackTrace();
              return successCount;
            }
            entity.setLocationAndAngles((double)x1,(double)y,(double)z1,worldServerIn.rand.nextFloat() * 360.0F,0.0F);
            Event.Result canSpawn=ForgeEventFactory.canEntitySpawn(entity,worldServerIn,x1,(float)y,z1);
            if (canSpawn == Event.Result.ALLOW || (canSpawn == Event.Result.DEFAULT && (entity.getCanSpawnHere() && entity.isNotColliding()))) {
              if (!ForgeEventFactory.doSpecialSpawn(entity,worldServerIn,x1,(float)y,z1)) {
                entity.onInitialSpawn(worldServerIn.getDifficultyForLocation(new BlockPos(entity)),null);
              }
              if (entity.isNotColliding()) {
                ++successCount;
                worldServerIn.spawnEntity(entity);
              }
 else {
                entity.setDead();
              }
            }
          }
        }
      }
    }
  }
  return successCount;
}

Fixed version (ground truth):
public int doCustomSpawning(WorldServer worldServerIn){
  this.chunksForSpawning.clear();
  int chunkCount=0;
  int successCount=0;
  for (  EntityPlayer entityplayer : worldServerIn.playerEntities) {
    if (!entityplayer.isSpectator()) {
      int playerX=MathHelper.floor(entityplayer.posX / 16.0D);
      int playerY=MathHelper.floor(entityplayer.posZ / 16.0D);
      final int center=8;
      for (int x=-center; x <= center; ++x) {
        for (int z=-center; z <= center; ++z) {
          boolean border=x == -center || x == center || z == -center || z == center;
          ChunkPos chunkpos=new ChunkPos(x + playerX,z + playerY);
          if (!this.chunksForSpawning.contains(chunkpos)) {
            ++chunkCount;
            if (!border && worldServerIn.getWorldBorder().contains(chunkpos)) {
              PlayerChunkMapEntry entry=worldServerIn.getPlayerChunkMap().getEntry(chunkpos.x,chunkpos.z);
              if (entry != null && entry.isSentToPlayers()) {
                this.chunksForSpawning.add(chunkpos);
              }
            }
          }
        }
      }
    }
  }
  for (  PrimitiveMobsSpawnEntry entry : PrimitiveMobsSpawnList.getSpawnEntries()) {
    int entityCount=worldServerIn.countEntities(entry.entityClass);
    int max=Math.round((float)chunkCount * entry.rarity * 0.1F);
    if (entityCount <= max) {
      List<ChunkPos> shuffled=Lists.newArrayList(this.chunksForSpawning);
      Collections.shuffle(shuffled);
      for (      ChunkPos chunk : shuffled) {
        BlockPos pos=getRandomChunkPosition(worldServerIn,chunk.x,chunk.z);
        int x=pos.getX();
        int y=pos.getY();
        int z=pos.getZ();
        IBlockState state=worldServerIn.getBlockState(pos);
        float x1=(float)x + 0.5F;
        float z1=(float)z + 0.5F;
        if (!state.isNormalCube() && !worldServerIn.isAnyPlayerWithinRangeAt((double)x1,(double)y,(double)z1,24.0D)) {
          Biome biome=worldServerIn.getBiome(pos);
          if (!entry.isBiomeSuitable(biome)) {
            continue;
          }
          if (WorldEntitySpawner.canCreatureTypeSpawnAtLocation(EntitySpawnPlacementRegistry.getPlacementForEntity(entry.entityClass),worldServerIn,pos)) {
            EntityLiving entity;
            try {
              entity=(EntityLiving)entry.entityClass.getConstructor(new Class[]{World.class}).newInstance(new Object[]{worldServerIn});
            }
 catch (            Exception exception) {
              exception.printStackTrace();
              return successCount;
            }
            entity.setLocationAndAngles((double)x1,(double)y,(double)z1,worldServerIn.rand.nextFloat() * 360.0F,0.0F);
            Event.Result canSpawn=ForgeEventFactory.canEntitySpawn(entity,worldServerIn,x1,(float)y,z1);
            if (canSpawn == Event.Result.ALLOW || (canSpawn == Event.Result.DEFAULT && (entity.getCanSpawnHere() && entity.isNotColliding()))) {
              if (!ForgeEventFactory.doSpecialSpawn(entity,worldServerIn,x1,(float)y,z1)) {
                entity.onInitialSpawn(worldServerIn.getDifficultyForLocation(new BlockPos(entity)),null);
              }
              if (entity.isNotColliding()) {
                ++successCount;
                worldServerIn.spawnEntity(entity);
              }
 else {
                if (entity instanceof EntityMotherSpider) {
                  PrimitiveMobsLogger.PMlogger.info("String_Node_Str" + "String_Node_Str" + entity.posX + "String_Node_Str"+ entity.posY+ "String_Node_Str"+ entity.posZ);
                }
                entity.setDead();
              }
            }
          }
        }
      }
    }
  }
  return successCount;
}