--- old/src/jdk/nashorn/internal/objects/NativeRegExp.java 2013-02-05 20:04:18.604271341 +0530 +++ new/src/jdk/nashorn/internal/objects/NativeRegExp.java 2013-02-05 20:04:18.452270591 +0530 @@ -675,7 +675,7 @@ start = matcher.find(start) ? matcher.start() : -1; if (global) { - setLastIndex(matcher.end()); + setLastIndex(start == -1? -1 : matcher.end()); } return start; --- /dev/null 2013-02-05 17:07:01.494007089 +0530 +++ new/test/script/basic/JDK-8007522.js 2013-02-05 20:04:19.100273803 +0530 @@ -0,0 +1,13 @@ +/** + * JDK-8007522: IllegalStateException thrown from String.prototype.search function + * + * @test + * @run + */ + +var str = "hello"; +// search used to result in IllegalStateException +if (str.search(/foo/g) != -1) { + fail("String.prototype.search failed"); +} +