RFR: 8370975: Test runtime/ErrorHandling/AccessZeroNKlassHitsProtectionZone.java can still fail on macos 26

Stefan Karlsson stefank at openjdk.org
Fri Oct 31 08:41:28 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 didn't work because by default regular expressions do not match across newlines.
> 
> I fixed this by re-working `OutputAnalyzer::match()`, etc, to use `Pattern.MULTILINE`.
> 
> I tried rerunning the test on macos 26 but couldn't reproduce the condition in the bug report. However, I added sanity test in this version (https://github.com/openjdk/jdk/commit/e690e97262575d083017635fa837ab267686bfe9) and the new regexp seems to catch the output and correctly come to this part of the test case:
> 
> 
> if (forceBase >= end) {
>     throw new SkippedException("Failed to force ccs to any of the given bases. Skipping test.");
> }

I took a closer look at this and I think the crucial part is that we are using `find` and not the change to use `MULTILINE`. `MULTILINE` seems to only be needed if you want to use `^` and `$` in your regex.

I added some temporary test to OutputAnalyzerTest to show this:

    public static boolean findIn(String regex, String... strings) {
        Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);
        for (String string : strings) {
            if (pattern.matcher(string).find()) {
                return true;
            }
        }

        return false;
    }

    private static void testFindIn() {
        String stdout = "some stdout";
        String stderr = "A little dog\nThe small cat\nA small horse";
        
        check(findIn("little", stdout, stderr));
        
        // Does not work with matches() `.` doesn't matche newlines
        check(findIn(".*A little dog.*", stdout, stderr));
        check(findIn("A.*", stdout, stderr));
        check(findIn("T.*", stdout, stderr));
        check(findIn(".*cat", stdout, stderr));
        check(findIn(".*horse", stdout, stderr));
        check(!findIn("frog", stdout, stderr));
        
        // Does not require multi-line
        check(findIn("dog\nThe", stdout, stderr));

        // Requires MULTILINE
        check(findIn("^The small cat", stdout, stderr));
        check(findIn("The small cat$", stdout, stderr));
        check(findIn("^The small cat$", stdout, stderr));
    }

    private static void check(boolean b) {
        if (!b) {
            throw new RuntimeException("Check failed");
        }
    }


Now play around with changing the `find` to `matches` and/or removing `MULTILINE`.

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

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

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


More information about the hotspot-runtime-dev mailing list