diff --git a/src/hotspot/share/utilities/vmError.cpp b/src/hotspot/share/utilities/vmError.cpp index ef04d69ee99..8131df80c0e 100644 --- a/src/hotspot/share/utilities/vmError.cpp +++ b/src/hotspot/share/utilities/vmError.cpp @@ -136,7 +136,9 @@ static const char* env_list[] = { nullptr // End marker. }; -// A simple parser for -XX:OnError, usage: +// A simple parser for lists of commands such as -XX:OnError and -XX:OnOutOfMemoryError +// Command list (ptr) is expected to be a sequence of commands delineated by semicolons and/or newlines. +// Usage: // ptr = OnError; // while ((cmd = next_OnError_command(buffer, sizeof(buffer), &ptr) != nullptr) // ... ... @@ -145,13 +147,13 @@ static char* next_OnError_command(char* buf, int buflen, const char** ptr) { const char* cmd = *ptr; - // skip leading blanks or ';' - while (*cmd == ' ' || *cmd == ';') cmd++; + // skip leading blanks, ';' or newlines + while (*cmd == ' ' || *cmd == ';' || *cmd == '\n') cmd++; if (*cmd == '\0') return nullptr; const char * cmdend = cmd; - while (*cmdend != '\0' && *cmdend != ';') cmdend++; + while (*cmdend != '\0' && *cmdend != ';' && *cmdend != '\n') cmdend++; Arguments::copy_expand_pid(cmd, cmdend - cmd, buf, buflen); diff --git a/test/hotspot/jtreg/runtime/ErrorHandling/TestOnError.java b/test/hotspot/jtreg/runtime/ErrorHandling/TestOnError.java index 53410c5379c..41f2c5eeb42 100644 --- a/test/hotspot/jtreg/runtime/ErrorHandling/TestOnError.java +++ b/test/hotspot/jtreg/runtime/ErrorHandling/TestOnError.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -40,7 +40,10 @@ public class TestOnError { public static void main(String[] args) throws Exception { String msg = "Test Succeeded"; + String msg1 = "OnError Test Message1"; + String msg2 = "OnError Test Message2"; + // Basic OnError test: ProcessBuilder pb = ProcessTools.createLimitedTestJavaProcessBuilder( "-XX:-CreateCoredumpOnCrash", "-XX:ErrorHandlerTest=14", // trigger potential SEGV @@ -59,6 +62,30 @@ public class TestOnError { both get written to stdout. */ output.stdoutShouldMatch("^" + msg); // match start of line only + + // Test multiple OnError arguments: + pb = ProcessTools.createLimitedTestJavaProcessBuilder( + "-XX:-CreateCoredumpOnCrash", + "-XX:ErrorHandlerTest=14", + "-XX:OnError=echo " + msg1, + "-XX:OnError=echo " + msg2, + TestOnError.class.getName()); + + output = new OutputAnalyzer(pb.start()); + output.stdoutShouldMatch("^" + msg1); + output.stdoutShouldMatch("^" + msg2); + + // Test one argument with multiple commands using ; separator: + pb = ProcessTools.createLimitedTestJavaProcessBuilder( + "-XX:-CreateCoredumpOnCrash", + "-XX:ErrorHandlerTest=14", + "-XX:OnError=echo " + msg1 + ";echo " + msg2, + TestOnError.class.getName()); + + output = new OutputAnalyzer(pb.start()); + output.stdoutShouldMatch("^" + msg1); + output.stdoutShouldMatch("^" + msg2); + System.out.println("PASSED"); } }