Weird -1 OutOfBoundException in the path check