Java long array index out of bounds exception -1

Thank you. This is a great method and there is no problem anymore. To reduce the volume, it is better to cut the area first.