Matcher: Adopt behavior changes forgotten in update to OpenJDK 8.

This is step 5 of verifying Matcher.java vs. OpenJDK 8u121-b13.

Matcher.java was never properly updated from OpenJDK 7u40 to OpenJDK 8
(u60, u121-b13).

This CL adopts the following behavior changes that were thus forgotten,
and adds unit tests enforcing them:

replaceFirst()
  - Adopt the following behavior even when there is no match:
   - still throw NPE
   - don't reset()
  - Previously, the NPE was not thrown and the Matcher was reset().

start(int group), end(int group):
  - throw IOOBE rather than ArrayIndexOutOfBoundsException if group < 0 or group > groupCount

appendReplacement(StringBuffer, String):
  - if replacement ends in \ or $ then the method now throws IAE;
    the old code only checked for training \ and threw an IOOBE instead
    of IAE. This behavior change required updating an old regression
    test from Harmony to expect the new behavior.
  - Note: The implementation of appendReplacement() appears to have
    previously been done independently from the upstream code. Its
    implementation could be changed to be based on / much more similar
    to upstream code, but this is not done as part of this CL.

Test: Before but not after this CL, the exceptions encountered by the
    out-of-bounds tests added to OldMatcherTest were specifically
    instances of ArrayIndexOutOfBoundsExceptions.
    The tests as written don't care about the kind of IOOBE they
    encounter, so they pass both before and after this CL.
Test: testReplaceFirst_null_match passes both before and after this CL.
Test: All other added tests fail before this CL but pass after this CL.
Test: CtsLibcoreTestCases
Bug: 80416774

Change-Id: Ibdee4976f5033c7913fa98a65475f2c7a310ebc9
4 files changed