RFR: 8370975: OutputAnalyzer.matches() should use Matcher with Pattern.MULTILINE [v2]

Ioi Lam iklam at openjdk.org
Tue Nov 4 09:13:25 UTC 2025


On Tue, 4 Nov 2025 09:01:36 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:
> 
>   Refactored the various "match" methods in OutputAnalyzer; added tests; reverted changes in AccessZeroNKlassHitsProtectionZone.java

Hi Stefan, thanks for looking into this.

> So, I would prefer to see the following:
> 
> 1. Fix the title to indicate that your updating the OutputAnalyzer
> 2. Fix the summary that states that MULTILINE is needed to match over newlines
> 3. Introduce the new "find" function (or rename matches)
> 4. Add tests
> 5. Preferably, use one RFE for the above enhancements and Bug for the test failure

I fixed the title, updated the summary and added test cases.

I didn't use "find", as all the existing methods in OutputAnalyzer use "match".

The bug is in OutputAnalyzer only. The test case AccessZeroNKlassHitsProtectionZone.java is correct in its current form. So I will use this PR to fix `OutputAnalyzer.matches()`.

-------------

PR Comment: https://git.openjdk.org/jdk/pull/28077#issuecomment-3484765891


More information about the hotspot-runtime-dev mailing list