RFR: 8370975: OutputAnalyzer.matches() should use Matcher with Pattern.MULTILINE [v4]
Stefan Karlsson
stefank at openjdk.org
Wed Nov 5 13:58:37 UTC 2025
On Tue, 4 Nov 2025 11:56:52 GMT, Ioi Lam <iklam at openjdk.org> wrote:
>> In the previous fix (https://github.com/openjdk/jdk/pull/28035), I added `OutputAnalyzer::match(String regexp)`, but it uses `String.matches()` which has different semantics than the existing "match" functions such as `OutputAnalyzer::shouldMatch()`.
>>
>> `String.matches()` is a poor choice for matching the stdout/stderr in `OutputAnalyzer`:
>>
>> - It requires a full match, so you need to use `haystackString.matches(".*needle.*")`
>> - But `.*` doesn't match across newlines, so it's basically useless for most program output.
>>
>> That's why the pattern in the previous fix in AccessZeroNKlassHitsProtectionZone.java (https://github.com/openjdk/jdk/pull/28035) doesn't work:
>>
>> https://github.com/openjdk/jdk/blame/e4aed95cac343f1339b9bc87721561bdc4c2f5ad/test/hotspot/jtreg/runtime/ErrorHandling/AccessZeroNKlassHitsProtectionZone.java#L146
>>
>> I fixed this by re-working `OutputAnalyzer::match()`, etc, to do the same thing as `OutputAnalyzer::shouldMatch()`. I also refactored the code to consolidate most of the regexp handling code to the two `matchesHelper()` methods.
>
> Ioi Lam has updated the pull request incrementally with one additional commit since the last revision:
>
> Use String... as suggested by @stefank
Marked as reviewed by stefank (Reviewer).
Looks good.
-------------
PR Review: https://git.openjdk.org/jdk/pull/28077#pullrequestreview-3422216751
PR Comment: https://git.openjdk.org/jdk/pull/28077#issuecomment-3491355552
More information about the hotspot-runtime-dev
mailing list