Program: 33851
Project: 33851
Buggy source:
/** 
 * Teleport to a safe spot on an island
 * @param plugin
 * @param entity
 * @param islandLoc
 */
public SafeSpotTeleport(final ASkyBlock plugin,final Entity entity,final Location islandLoc,final int homeNumber,final String failureMessage,final boolean setHome){
  Island island=plugin.getGrid().getIslandAt(islandLoc);
  if (island != null) {
    final World world=islandLoc.getWorld();
    List<ChunkSnapshot> chunkSnapshot=new ArrayList<ChunkSnapshot>();
    chunkSnapshot.add(island.getCenter().toVector().toLocation(world).getChunk().getChunkSnapshot());
    for (int x=islandLoc.getChunk().getX() - 1; x <= islandLoc.getChunk().getX() + 1; x++) {
      for (int z=islandLoc.getChunk().getZ() - 1; z <= islandLoc.getChunk().getZ() + 1; z++) {
        if (x != islandLoc.getChunk().getX() || z != islandLoc.getChunk().getZ()) {
          chunkSnapshot.add(world.getChunkAt(x,z).getChunkSnapshot());
        }
      }
    }
    for (int x=island.getMinProtectedX() / 16; x <= (island.getMinProtectedX() + island.getProtectionSize() - 1) / 16; x++) {
      for (int z=island.getMinProtectedZ() / 16; z <= (island.getMinProtectedZ() + island.getProtectionSize() - 1) / 16; z++) {
        chunkSnapshot.add(world.getChunkAt(x,z).getChunkSnapshot());
      }
    }
    final List<ChunkSnapshot> finalChunk=chunkSnapshot;
    int maxHeight=world.getMaxHeight() - 2;
    if (world.getEnvironment().equals(Environment.NETHER)) {
      maxHeight-=20;
    }
    final int worldHeight=maxHeight;
    plugin.getServer().getScheduler().runTaskAsynchronously(plugin,new Runnable(){
      @SuppressWarnings("String_Node_Str") @Override public void run(){
        int x=0;
        int y=0;
        int z=0;
        ChunkSnapshot safeChunk=null;
        ChunkSnapshot portalChunk=null;
        boolean safeSpotFound=false;
        Vector safeSpotInChunk=null;
        Vector portalPart=null;
        double distance=0D;
        double safeDistance=0D;
        for (        ChunkSnapshot chunk : finalChunk) {
          for (x=0; x < 16; x++) {
            for (z=0; z < 16; z++) {
              for (y=Math.min(chunk.getHighestBlockYAt(x,z),worldHeight); y >= 0; y--) {
                if (!setHome && chunk.getBlockTypeId(x,y,z) == Material.PORTAL.getId()) {
                  if (portalPart == null || (distance > islandLoc.toVector().distanceSquared(new Vector(x,y,z)))) {
                    portalChunk=chunk;
                    portalPart=new Vector(x,y,z);
                    distance=portalPart.distanceSquared(islandLoc.toVector());
                  }
                }
                if (!safeSpotFound || (safeDistance > islandLoc.toVector().distanceSquared(new Vector(x,y,z)))) {
                  if (checkBlock(chunk,x,y,z,worldHeight)) {
                    safeChunk=chunk;
                    safeSpotFound=true;
                    safeSpotInChunk=new Vector(x,y,z);
                    safeDistance=islandLoc.toVector().distanceSquared(safeSpotInChunk);
                  }
                }
              }
            }
          }
        }
        if (portalPart != null) {
          x=portalPart.getBlockX();
          y=portalPart.getBlockY();
          z=portalPart.getBlockZ();
          while (portalChunk.getBlockTypeId(x,y,z) == Material.PORTAL.getId()) {
            y--;
          }
          if (checkBlock(portalChunk,x,y,z,worldHeight)) {
            safeSpotFound=true;
            safeSpotInChunk=new Vector(x,y,z);
            safeChunk=portalChunk;
          }
        }
        if (safeChunk != null && safeSpotFound) {
          final Vector spot=new Vector((16 * safeChunk.getX()) + 0.5D,1,(16 * safeChunk.getZ()) + 0.5D).add(safeSpotInChunk);
          plugin.getServer().getScheduler().runTask(plugin,new Runnable(){
            @Override public void run(){
              Location destination=spot.toLocation(islandLoc.getWorld());
              if (setHome && entity instanceof Player) {
                plugin.getPlayers().setHomeLocation(entity.getUniqueId(),destination,homeNumber);
              }
              Vector velocity=entity.getVelocity();
              entity.teleport(destination);
              entity.setVelocity(velocity);
            }
          }
);
        }
 else {
          plugin.getServer().getScheduler().runTask(plugin,new Runnable(){
            @Override public void run(){
              if (entity instanceof Player) {
                if (!failureMessage.isEmpty()) {
                  Util.sendMessage(((Player)entity),failureMessage);
                }
 else {
                  Util.sendMessage(((Player)entity),ChatColor.RED + plugin.myLocale(((Player)entity).getUniqueId()).warpserrorNotSafe);
                }
              }
            }
          }
);
        }
      }
      /** 
 * Returns true if the location is a safe one.
 * @param chunk
 * @param x
 * @param y
 * @param z
 * @param worldHeight 
 * @return
 */
      @SuppressWarnings("String_Node_Str") private boolean checkBlock(      ChunkSnapshot chunk,      int x,      int y,      int z,      int worldHeight){
        int type=chunk.getBlockTypeId(x,y,z);
        if (type != 0) {
          int space1=chunk.getBlockTypeId(x,Math.min(y + 1,worldHeight),z);
          int space2=chunk.getBlockTypeId(x,Math.min(y + 2,worldHeight),z);
          if ((space1 == 0 && space2 == 0) || (space1 == Material.PORTAL.getId() || space2 == Material.PORTAL.getId())) {
            Material mat=Material.getMaterial(type);
            if (!mat.toString().contains("String_Node_Str") && !mat.toString().contains("String_Node_Str") && !mat.toString().contains("String_Node_Str")&& !mat.toString().contains("String_Node_Str")) {
switch (mat) {
case ANVIL:
case BARRIER:
case BOAT:
case CACTUS:
case DOUBLE_PLANT:
case ENDER_PORTAL:
case FIRE:
case FLOWER_POT:
case LADDER:
case LAVA:
case LEVER:
case LONG_GRASS:
case PISTON_EXTENSION:
case PISTON_MOVING_PIECE:
case PORTAL:
case SIGN_POST:
case SKULL:
case STANDING_BANNER:
case STATIONARY_LAVA:
case STATIONARY_WATER:
case STONE_BUTTON:
case TORCH:
case TRIPWIRE:
case WATER:
case WEB:
case WOOD_BUTTON:
                break;
default :
              return true;
          }
        }
      }
    }
    return false;
  }
}
);
}
}

Fixed version (ground truth):
/** 
 * Teleport to a safe spot on an island
 * @param plugin
 * @param entity that is being teleported
 * @param islandLoc - the location of the island
 * @param homeNumber - the home number to set if setHome is true
 * @param failureMessage - the message to show the player if this cannot be done
 * @param setHome - if true, the resulting teleport location should become the player's home
 */
public SafeSpotTeleport(final ASkyBlock plugin,final Entity entity,final Location islandLoc,final int homeNumber,final String failureMessage,final boolean setHome){
  Island island=plugin.getGrid().getIslandAt(islandLoc);
  if (island != null) {
    final World world=islandLoc.getWorld();
    List<ChunkSnapshot> chunkSnapshot=new ArrayList<ChunkSnapshot>();
    chunkSnapshot.add(island.getCenter().toVector().toLocation(world).getChunk().getChunkSnapshot());
    for (int x=islandLoc.getChunk().getX() - 1; x <= islandLoc.getChunk().getX() + 1; x++) {
      for (int z=islandLoc.getChunk().getZ() - 1; z <= islandLoc.getChunk().getZ() + 1; z++) {
        if (x != islandLoc.getChunk().getX() || z != islandLoc.getChunk().getZ()) {
          chunkSnapshot.add(world.getChunkAt(x,z).getChunkSnapshot());
        }
      }
    }
    for (int x=island.getMinProtectedX() / 16; x <= (island.getMinProtectedX() + island.getProtectionSize() - 1) / 16; x++) {
      for (int z=island.getMinProtectedZ() / 16; z <= (island.getMinProtectedZ() + island.getProtectionSize() - 1) / 16; z++) {
        chunkSnapshot.add(world.getChunkAt(x,z).getChunkSnapshot());
      }
    }
    final List<ChunkSnapshot> finalChunk=chunkSnapshot;
    int maxHeight=world.getMaxHeight() - 2;
    if (world.getEnvironment().equals(Environment.NETHER)) {
      maxHeight-=20;
    }
    final int worldHeight=maxHeight;
    plugin.getServer().getScheduler().runTaskAsynchronously(plugin,new Runnable(){
      @SuppressWarnings("String_Node_Str") @Override public void run(){
        int x=0;
        int y=0;
        int z=0;
        ChunkSnapshot safeChunk=null;
        ChunkSnapshot portalChunk=null;
        boolean safeSpotFound=false;
        Vector safeSpotInChunk=null;
        Vector portalPart=null;
        double distance=0D;
        double safeDistance=0D;
        for (        ChunkSnapshot chunk : finalChunk) {
          for (x=0; x < 16; x++) {
            for (z=0; z < 16; z++) {
              for (y=Math.min(chunk.getHighestBlockYAt(x,z),worldHeight); y >= 0; y--) {
                if (!setHome && chunk.getBlockTypeId(x,y,z) == Material.PORTAL.getId()) {
                  if (portalPart == null || (distance > islandLoc.toVector().distanceSquared(new Vector(x,y,z)))) {
                    portalChunk=chunk;
                    portalPart=new Vector(x,y,z);
                    distance=portalPart.distanceSquared(islandLoc.toVector());
                  }
                }
                if (!safeSpotFound || (safeDistance > islandLoc.toVector().distanceSquared(new Vector(x,y,z)))) {
                  if (checkBlock(chunk,x,y,z,worldHeight)) {
                    safeChunk=chunk;
                    safeSpotFound=true;
                    safeSpotInChunk=new Vector(x,y,z);
                    safeDistance=islandLoc.toVector().distanceSquared(safeSpotInChunk);
                  }
                }
              }
            }
          }
        }
        if (portalPart != null) {
          x=portalPart.getBlockX();
          y=portalPart.getBlockY();
          z=portalPart.getBlockZ();
          while (portalChunk.getBlockTypeId(x,y,z) == Material.PORTAL.getId()) {
            y--;
          }
          if (checkBlock(portalChunk,x,y,z,worldHeight)) {
            safeSpotFound=true;
            safeSpotInChunk=new Vector(x,y,z);
            safeChunk=portalChunk;
          }
        }
 else {
          if (entity instanceof Player) {
            Player player=(Player)entity;
            HashMap<Integer,Location> teleport=plugin.getPlayers().getHomeLocations(player.getUniqueId());
            for (            Entry<Integer,Location> loc : teleport.entrySet()) {
              if (loc.getKey() < 0) {
                if (loc.getValue().getWorld().equals(islandLoc.getWorld())) {
                  final Location destination=loc.getValue().add(new Vector(0.5D,0,0.5D));
                  plugin.getServer().getScheduler().runTask(plugin,new Runnable(){
                    @Override public void run(){
                      if (setHome) {
                        plugin.getPlayers().setHomeLocation(entity.getUniqueId(),destination,homeNumber);
                      }
                      Vector velocity=entity.getVelocity();
                      entity.teleport(destination);
                      entity.setVelocity(velocity);
                    }
                  }
);
                  return;
                }
              }
            }
          }
        }
        if (safeChunk != null && safeSpotFound) {
          final Vector spot=new Vector((16 * safeChunk.getX()) + 0.5D,1,(16 * safeChunk.getZ()) + 0.5D).add(safeSpotInChunk);
          plugin.getServer().getScheduler().runTask(plugin,new Runnable(){
            @Override public void run(){
              Location destination=spot.toLocation(islandLoc.getWorld());
              if (setHome && entity instanceof Player) {
                plugin.getPlayers().setHomeLocation(entity.getUniqueId(),destination,homeNumber);
              }
              Vector velocity=entity.getVelocity();
              entity.teleport(destination);
              entity.setVelocity(velocity);
            }
          }
);
        }
 else {
          plugin.getServer().getScheduler().runTask(plugin,new Runnable(){
            @Override public void run(){
              if (entity instanceof Player) {
                if (!failureMessage.isEmpty()) {
                  Util.sendMessage(((Player)entity),failureMessage);
                }
 else {
                  Util.sendMessage(((Player)entity),ChatColor.RED + plugin.myLocale(((Player)entity).getUniqueId()).warpserrorNotSafe);
                }
              }
            }
          }
);
        }
      }
      /** 
 * Returns true if the location is a safe one.
 * @param chunk
 * @param x
 * @param y
 * @param z
 * @param worldHeight 
 * @return
 */
      @SuppressWarnings("String_Node_Str") private boolean checkBlock(      ChunkSnapshot chunk,      int x,      int y,      int z,      int worldHeight){
        int type=chunk.getBlockTypeId(x,y,z);
        if (type != 0) {
          int space1=chunk.getBlockTypeId(x,Math.min(y + 1,worldHeight),z);
          int space2=chunk.getBlockTypeId(x,Math.min(y + 2,worldHeight),z);
          if ((space1 == 0 && space2 == 0) || (space1 == Material.PORTAL.getId() || space2 == Material.PORTAL.getId())) {
            Material mat=Material.getMaterial(type);
            if (!mat.toString().contains("String_Node_Str") && !mat.toString().contains("String_Node_Str") && !mat.toString().contains("String_Node_Str")&& !mat.toString().contains("String_Node_Str")) {
switch (mat) {
case ANVIL:
case BARRIER:
case BOAT:
case CACTUS:
case DOUBLE_PLANT:
case ENDER_PORTAL:
case FIRE:
case FLOWER_POT:
case LADDER:
case LAVA:
case LEVER:
case LONG_GRASS:
case PISTON_EXTENSION:
case PISTON_MOVING_PIECE:
case PORTAL:
case SIGN_POST:
case SKULL:
case STANDING_BANNER:
case STATIONARY_LAVA:
case STATIONARY_WATER:
case STONE_BUTTON:
case TORCH:
case TRIPWIRE:
case WATER:
case WEB:
case WOOD_BUTTON:
                break;
default :
              return true;
          }
        }
      }
    }
    return false;
  }
}
);
}
}