I recently saw strange behavior in my application that I cannot explain. They are very rare, so I can not reproduce them. While the place where these problems occur is changing, the general part seems to be that the array changes size after it is created (I know this is not possible, which means weird behavior).
A few examples to clearly indicate:
java.lang.StringIndexOutOfBoundsException: String index out of range: 86 at java.lang.String.checkBounds(String.java:409) at java.lang.String.<init>(String.java:577) at com.acunia.fleet.diagnostics.providers.tacho.VDOKLineInputParser.getRealDriverID(Unknown Source)
The code that calls this:
public String getRealDriverID(byte[] buffer) { if (buffer.length > 86 && isDriverCardInserted(buffer)) { return new String(buffer, 70, 16); } return null; }
So, first we check that the buffer is large enough (over 86 bytes) before trying to create a string from them.
Second example:
java.lang.ArrayIndexOutOfBoundsException: -1 at java.lang.String.lastIndexOf(String.java:1889) at java.lang.String.lastIndexOf(String.java:1835) at java.lang.String.lastIndexOf(String.java:1817) at com.acunia.service.position.nmea.comm.CommPositionProvider.isValid(Unknown Source)
The line that raises this exception is:
int csi = line.lastIndexOf("*");
I looked at the source of openjdk String.java, but could not find the error if the arrays could not suddenly start resizing after they were created.
The only link I can find may be related to the openjdk error: https://bugs.openjdk.java.net/browse/JDK-6817012 . This error was marked as โnot a problemโ, although, while reading this, I canโt say if the problem is mentioned, which was mentioned as an error, or if the person who closed the error does not see why this error can cause Problems.
If anyone has encountered a similar problem, I would really like to hear about it. As it stands, the problem is too unstable to try to fix it using other versions of openjdk.
The problem was visible on:
hardware: custom arm platform java version "1.6.0_31" OpenJDK Runtime Environment (IcedTea6 1.13.3) (6b31-1.13.3-1~deb7u1) OpenJDK Zero VM (build 23.25-b01, mixed mode) Linux 3.2.0