Getting "ArrayIndexOutOfBoundsException: null" with NO stack trace

I found pretty much the same behavior with disappointing log as shown below:

java.lang.ArrayIndexOutOfBoundsException: null

In my case, the problem was in concurrent ArrayList.add calls (two separate threads added elements into shared unsynchronized list). The most interesting thing: first ArrayIndexOutOfBoundsException always had stacktrace and descriptive message, all future ArrayIndexOutOfBoundsExceptions were without stacktrace and message. Tried to reproduce on separate project with plain java threads - no luck (always got full stacktraces etc).

PS. OpenJDK 11, jetty server.


  1. String concatenated with a null reference might get you such a message:

    Object obj = null;
    throw new ArrayIndexOutOfBoundsException("" + obj);
    
  2. If you're using an Oracle JVM you may want to add -XX:-OmitStackTraceInFastThrow as an additional parameter to see if it helps. For some basic exceptions, the JVM reuses the same exception instance after a while, in which case there's no stack trace anymore. This option prevents the reuse, so you always get a stack trace.

Edit note: this last could also apply to a recent version of OpenJDK (e.g., 1.8)