Menu

#2 ArrayIndexOutOutOfBounds exception

open
nobody
None
5
2012-12-05
2007-03-02
Anonymous
No

Under certain circumstances the gridind value can be -1 when attempting to use it in the draw() method in the ValueAxis class. This causes an ArrayIndexOutOfBounds exception when drawing the graph...

I didn't fully understand what was going on in the code of that method, but here is some modified code that seems to fix the problem

int j = 0;
for (int i = 0; ylab[i].grid > 0; i++) {
j = i;
pixel = (int) (im.ysize / (scaledrange / ylab[i].grid));
if (gridind == -1 && pixel > 5) {
gridind = i;
break;
}
}
if (gridind < 0) {
gridind = j;
}

Discussion

  • Nobody/Anonymous

    Logged In: NO

    Although the above fix prevents the exception from occurring, sometimes, if the graph y-axis has very large values (thousands), the number of horizontal minor lines drawn will be too many and the graph will appear to be swamped with minor horizontal axis...

     
  • Ronny Standtke

    Ronny Standtke - 2009-10-11

    Two and a half years after someone reported this bug I also run into it. Here is the relevant part of the backtrace with JRobin 1.5.9.1:

    java.lang.ArrayIndexOutOfBoundsException: -1
    at org.jrobin.graph.ValueAxis.draw(ValueAxis.java:129)
    at org.jrobin.graph.RrdGraph.drawGrid(RrdGraph.java:212)
    at org.jrobin.graph.RrdGraph.createGraph(RrdGraph.java:93)
    at org.jrobin.graph.RrdGraph.<init>(RrdGraph.java:59)