Since I reported the bug, I thought I should at least also investigate it a bit further. I've been able to further simplify the pattern to reproduce the bug (see also on ideone.com).
System.out.println( "abaab".matches("(?x) (?: (?=(a+)) \\1 b )* x") ); // StringIndexOutOfBounds: -1The out of bounds index is the difference in length between the first and the second
Note that using reluctant
false. Only the greedy
*raises the exception.
It looks like the problem is triggered by the attempt to backtrack a greedy repetition when there's a reference to a capturing group inside a lookahead.