RFR: 8316879: RegionMatches1Tests fails if CompactStrings are disabled after JDK-8302163
Volker Simonis
simonis at openjdk.org
Mon Sep 25 17:08:13 UTC 2023
On Mon, 25 Sep 2023 15:52:12 GMT, Aleksei Voitylov <avoitylov at openjdk.org> wrote:
> test java.lang.String.RegionMatches1Tests fails on all platforms with -XX:-CompactStrings option and on ARM32 where Compact Strings is disabled by default. The fix is to return true immediately if len is negative, since for negative length this condition will never be satisfied.
>
> Testing: JCK, JTREG passed with the fix with -XX:-CompactStrings on x86_64 and on ARM32.
Nice catch, but I don't think your current fix is correct:
src/java.base/share/classes/java/lang/String.java line 2159:
> 2157: return false;
> 2158: }
> 2159: // Any strings match if length < 0
I don't think this fix works, because the specification says:
*The result is false if and only if at least one of the following is true:*
- `toffset` is negative.
- `ooffset` is negative.
- `toffset+len` is greater than the length of this String object.
- `ooffset+len` is greater than the length of the other argument.
- There is some nonnegative integer `k` less than `len` such that: `this.charAt(toffset + k) != other.charAt(ooffset + k)`
Now consider `"12345".regionMatches(10, "012345", 1, -3)`
With the current implementation, the call returns `false` because `toffset + len` == `10 + (-3)` == 7 > 5 == `"12345".length()`. With your fix, the call will succeed because `len` == `-3` < `0`.
-------------
Changes requested by simonis (Reviewer).
PR Review: https://git.openjdk.org/jdk/pull/15906#pullrequestreview-1642643067
PR Review Comment: https://git.openjdk.org/jdk/pull/15906#discussion_r1336170810
More information about the core-libs-dev
mailing list