JDK-8041998 : RegExp implementation is not thread-safe
  • Type: Bug
  • Component: core-libs
  • Sub-Component: jdk.nashorn
  • Affected Version: 8
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2014-04-28
  • Updated: 2014-07-29
  • Resolved: 2014-05-06
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8 JDK 9
8u20 b15Fixed 9Fixed
Description
The following script:

var Thread = java.lang.Thread;

function test_thread() {
  var line = 'content-type: text/html';
  while (1) {
    Thread.sleep(100);
    line.split(/: /);
  }
}

for (var i=0; i<5; i++) {
  new Thread(test_thread).start();
}

while (1) { Thread.sleep(1000); }

Throws:

java.lang.NullPointerException
at jdk.nashorn.internal.runtime.regexp.joni.Regex.matcher(Regex.java:148)
at jdk.nashorn.internal.runtime.regexp.joni.Regex.matcher(Regex.java:143)
at jdk.nashorn.internal.runtime.regexp.JoniRegExp$JoniMatcher.<init>(JoniRegExp.java:126)
at jdk.nashorn.internal.runtime.regexp.JoniRegExp.match(JoniRegExp.java:101)
at jdk.nashorn.internal.objects.NativeRegExp.execSplit(NativeRegExp.java:581)
at jdk.nashorn.internal.objects.NativeRegExp.split(NativeRegExp.java:824)
at jdk.nashorn.internal.objects.NativeString.split(NativeString.java:878)