1 /* 2 * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* 25 * @test TestUnrecognizedVMOptionsHandling 26 * @key gc 27 * @bug 8017611 28 * @summary Tests handling unrecognized VM options 29 * @library /testlibrary 30 * @modules java.base/sun.misc 31 * java.management 32 * @run main/othervm TestUnrecognizedVMOptionsHandling 33 */ 34 35 import jdk.test.lib.*; 36 37 public class TestUnrecognizedVMOptionsHandling { 38 39 public static void main(String args[]) throws Exception { 40 // The first two JAVA processes are expected to fail, but with a correct VM option suggestion 41 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( 42 "-XX:+UseDynamicNumberOfGcThreads", 43 "-version" 44 ); 45 OutputAnalyzer outputWithError = new OutputAnalyzer(pb.start()); 46 outputWithError.shouldContain("Did you mean '(+/-)UseDynamicNumberOfGCThreads'?"); 47 if (outputWithError.getExitValue() == 0) { 48 throw new RuntimeException("Not expected to get exit value 0"); 49 } 50 51 pb = ProcessTools.createJavaProcessBuilder( 52 "-XX:MaxiumHeapSize=500m", 53 "-version" 54 ); 55 outputWithError = new OutputAnalyzer(pb.start()); 56 outputWithError.shouldContain("Did you mean 'MaxHeapSize=<value>'?"); 57 if (outputWithError.getExitValue() == 0) { 58 throw new RuntimeException("Not expected to get exit value 0"); 59 } 60 61 // The last JAVA process should run successfully for the purpose of sanity check 62 pb = ProcessTools.createJavaProcessBuilder( 63 "-XX:+UseDynamicNumberOfGCThreads", 64 "-version" 65 ); 66 OutputAnalyzer outputWithNoError = new OutputAnalyzer(pb.start()); 67 outputWithNoError.shouldNotContain("Did you mean '(+/-)UseDynamicNumberOfGCThreads'?"); 68 outputWithNoError.shouldHaveExitValue(0); 69 } 70 } 71