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

Ioi Lam iklam at openjdk.org
Tue Nov 4 11:52:10 UTC 2025


> 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:

  Renamed matchesHelper() to findPattern()

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

Changes:
  - all: https://git.openjdk.org/jdk/pull/28077/files
  - new: https://git.openjdk.org/jdk/pull/28077/files/3b493855..b3feafc5

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jdk&pr=28077&range=02
 - incr: https://webrevs.openjdk.org/?repo=jdk&pr=28077&range=01-02

  Stats: 15 lines in 1 file changed: 2 ins; 0 del; 13 mod
  Patch: https://git.openjdk.org/jdk/pull/28077.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/28077/head:pull/28077

PR: https://git.openjdk.org/jdk/pull/28077


More information about the hotspot-runtime-dev mailing list