11/*
2- * Copyright (c) 2015, 2023 , Oracle and/or its affiliates. All rights reserved.
2+ * Copyright (c) 2015, 2025 , Oracle and/or its affiliates. All rights reserved.
33 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44 *
55 * This code is free software; you can redistribute it and/or modify it
@@ -40,7 +40,10 @@ public class TestOnError {
4040
4141 public static void main (String [] args ) throws Exception {
4242 String msg = "Test Succeeded" ;
43+ String msg1 = "OnError Test Message1" ;
44+ String msg2 = "OnError Test Message2" ;
4345
46+ // Basic OnError test:
4447 ProcessBuilder pb = ProcessTools .createLimitedTestJavaProcessBuilder (
4548 "-XX:-CreateCoredumpOnCrash" ,
4649 "-XX:ErrorHandlerTest=14" , // trigger potential SEGV
@@ -59,6 +62,30 @@ public static void main(String[] args) throws Exception {
5962 both get written to stdout.
6063 */
6164 output .stdoutShouldMatch ("^" + msg ); // match start of line only
65+
66+ // Test multiple OnError arguments:
67+ pb = ProcessTools .createLimitedTestJavaProcessBuilder (
68+ "-XX:-CreateCoredumpOnCrash" ,
69+ "-XX:ErrorHandlerTest=14" ,
70+ "-XX:OnError=echo " + msg1 ,
71+ "-XX:OnError=echo " + msg2 ,
72+ TestOnError .class .getName ());
73+
74+ output = new OutputAnalyzer (pb .start ());
75+ output .stdoutShouldMatch ("^" + msg1 );
76+ output .stdoutShouldMatch ("^" + msg2 );
77+
78+ // Test one argument with multiple commands using ; separator:
79+ pb = ProcessTools .createLimitedTestJavaProcessBuilder (
80+ "-XX:-CreateCoredumpOnCrash" ,
81+ "-XX:ErrorHandlerTest=14" ,
82+ "-XX:OnError=echo " + msg1 + ";echo " + msg2 ,
83+ TestOnError .class .getName ());
84+
85+ output = new OutputAnalyzer (pb .start ());
86+ output .stdoutShouldMatch ("^" + msg1 );
87+ output .stdoutShouldMatch ("^" + msg2 );
88+
6289 System .out .println ("PASSED" );
6390 }
6491}
0 commit comments