XChart
XChart copied to clipboard
IndexOutOfBoundsException introduced in 3.7.0 or 3.8.0
Hi, attached date+value series can be plotted in 3.6.6 without any errors. Yet in 3.8.0 (cannot use 3.7.0 as this release doesn't contain some of the class that 3.6.6 and 3.8.0 have) I got:
java.lang.IndexOutOfBoundsException: Index 46 out of bounds for length 46 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:372) at java.base/java.util.ArrayList.get(ArrayList.java:458) at org.knowm.xchart.internal.chartpart.AxisTickCalculator_Date.calculate(AxisTickCalculator_Date.java:201) at org.knowm.xchart.internal.chartpart.AxisTickCalculator_Date.<init>(AxisTickCalculator_Date.java:103) at org.knowm.xchart.internal.chartpart.Axis.getAxisTickCalculator(Axis.java:454) at org.knowm.xchart.internal.chartpart.Axis.getXAxisHeightHint(Axis.java:289) at org.knowm.xchart.internal.chartpart.Axis.preparePaint(Axis.java:155) at org.knowm.xchart.internal.chartpart.AxisPair.paint(AxisPair.java:121) at org.knowm.xchart.XYChart.paint(XYChart.java:416) at org.knowm.xchart.BitmapEncoder.getBufferedImage(BitmapEncoder.java:281) at org.knowm.xchart.BitmapEncoder.saveBitmap(BitmapEncoder.java:134) at org.knowm.xchart.BitmapEncoder.saveBitmap(BitmapEncoder.java:109)
which corresponds to unverified use of index in a loop here:
double gridStep = timeSpans.get(++index).getUnitAmount() * timeSpans.get(index).getMagnitude(); // in time units (ms) *
This error most probably has been introduced as part of this fix: https://github.com/knowm/XChart/issues/527 (@timmolter)
example data that leads to this error:
I have the same issue on 3.8.0 and 3.8.1. On 3.7.0 it works, though.