jchambers / jchambers/jeospatial

Getting a java.lang.IndexOutOfBoundsException:

Open
#9 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
43
Forks
14
PR merge metrics
No merged PRs in 30d

Description

I am getting below error when trying to handle an index of size 100000000.

Sample program

```java
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import com.eatthepath.jeospatial.VPTreeGeospatialIndex;
import com.eatthepath.jeospatial.GeospatialPoint;

public class GeoIndexTest {

public static void main(String[] args) {
List points = new ArrayList<>();

final Random r = new Random();

long t1 = System.currentTimeMillis();
for (int i = 0; i < 100000000; i++) {

points.add(new GeospatialPoint() {

@Override
public double getLatitude() {
return (r.nextDouble() * -180.0) + 90.0;
}

@Override
public double getLongitude() {
return (r.nextDouble() * -360.0) + 180.0;
}

});
}
long t2 = System.currentTimeMillis();
System.out.println("Inserted in " + (t2 - t1));

points.add(new GeospatialPoint(){

@Override
public double getLatitude() {
// TODO Auto-generated method stub
return 39.165325d;
}

@Override
public double getLongitude() {
// TODO Auto-generated method stub
return -86.5263857d;
}

});

VPTreeGeospatialIndex vpti = new VPTreeGeospatialIndex(points);

// indiana
List allPointsInBoundingBox = vpti.getAllPointsInBoundingBox(37.96, -87.54d, 41.76, -84.81d);
System.out.println("Results : " + allPointsInBoundingBox.size());
long t3 = System.currentTimeMillis();
System.out.println("Searched in " + (t3 - t2));
}
}
```

Output
```bash
Exception in thread "main" java.lang.IndexOutOfBoundsException: Index -65467727 out of bounds for length 100000001
at java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:64)
at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:70)
at java.base/jdk.internal.util.Preconditions.checkIndex(Preconditions.java:248)
at java.base/java.util.Objects.checkIndex(Objects.java:373)
at java.base/java.util.ArrayList.get(ArrayList.java:426)
at com.eatthepath.jvptree.util.SamplingMedianDistanceThresholdSelectionStrategy.getSampledPoints(SamplingMedianDistanceThresholdSelectionStrategy.java:61)
at com.eatthepath.jvptree.util.SamplingMedianDistanceThresholdSelectionStrategy.selectThreshold(SamplingMedianDistanceThresholdSelectionStrategy.java:43)
at com.eatthepath.jvptree.VPTreeNode.anneal(VPTreeNode.java:88)
at com.eatthepath.jvptree.VPTreeNode.(VPTreeNode.java:62)
at com.eatthepath.jvptree.VPTree.(VPTree.java:129)
at com.eatthepath.jvptree.VPTree.(VPTree.java:70)
at com.eatthepath.jeospatial.VPTreeGeospatialIndex.(VPTreeGeospatialIndex.java:24)
at edu.iu.iuni.moe.GeoIndexTest.main(GeoIndexTest.java:53)
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.