Verify Matcher vs. OpenJDK 8u121-b13, step 7.

Adopt upstream behavior in some more corner cases. This upstream
behavior has existed since at least OpenJDK 7u40; Android's previously
never adopted it:

- group(int): Throw IOOBE rather than AIOOBE when the index is out of
  bounds. Unlike the similar behavior change already adopted for
  start(int),  end(int) in the parent CL, the change in group(int)
  was introduced in commit 075cf9ab88476958db0dd3ca80e21802fc623f66.
  Since start(int), end(int) changed upstream, this CL also changes
  group(int) in a similar fashion to match the behavior that that
  particular method already had upstream since at least OpenJDK 7u40.
- find(int): When throwing IOOBE, do not reset() the Matcher as a side
  effect.
  This matches a similar behavior change in replaceFirst()
  in the parent CL. The behavior of reset()ing early was introduced in
  commit faa2342e585ce148d6de982106ec7b5735f07f1f (July 2017) and
  appears accidental.
- replaceAll(String), replaceFirst(String): Adopt upstream implementations.
  The only behavior difference should be that after this CL, the
  methods now return the original input String rather than allocating
  a copy. The documentation mentions that the method returns "The string
  constructed by [...]", but it appears reasonable (and potentially more
  memory efficient) to not allocate a new String when not required.
  Because either behavior is reasonable, this CL does not add test
  coverage to be opinionated either way.

Test: CtsLibcoreTestCases
Bug: 80416774

Change-Id: I40ba8aebf4a67f9496b37d6f7f8627e687a2f0f3
1 file changed