Integrated: 8370975: OutputAnalyzer.matches() should use Matcher with Pattern.MULTILINE
Ioi Lam
iklam at openjdk.org
Thu Nov 6 04:51:16 UTC 2025
On Thu, 30 Oct 2025 22:53:59 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.
This pull request has now been integrated.
Changeset: 3f40f4c3
Author: Ioi Lam <iklam at openjdk.org>
URL: https://git.openjdk.org/jdk/commit/3f40f4c362f6ff4d1ec7d513b4690ed5fade3e2a
Stats: 111 lines in 2 files changed: 87 ins; 13 del; 11 mod
8370975: OutputAnalyzer.matches() should use Matcher with Pattern.MULTILINE
Reviewed-by: stefank
-------------
PR: https://git.openjdk.org/jdk/pull/28077
More information about the hotspot-runtime-dev
mailing list