skipWhiteSpacereference with the regex literal it references, then the rest of the code always runs to completion without any failures
Do you have Java version & full stacktrace by any chance? I'm not familiar with Nashorn at all, but this from quick googling sounds suspiciously similar: http://nashorn.36665.n7.nabble.com/ArrayIndexOutOfBoundsException-and-NPE-in-regexp-Code-td3139.html
We've run into a few cases where Joni (regex) is not safe across threads. This has been fixed in 8u20 http://hg.openjdk.java.net/jdk8u/jdk8u-dev/nashorn/rev/9ad26ed8cc97 . The workaround is to use new RegExp("...") so that the regexp is not shared. If you are iterating through a loop, hoist the expression outside the loop.
The workaround is to use new RegExp("...") so that the regexp is not shared