1 /* 2 * Copyright (c) 2016, 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 26 * @bug 8162415 27 * @summary Test warnings for ignored properties. 28 * @modules java.base/jdk.internal.misc 29 * @library /test/lib 30 */ 31 32 import java.util.Map; 33 import jdk.test.lib.process.OutputAnalyzer; 34 import jdk.test.lib.process.ProcessTools; 35 36 // Test that the VM behaves correctly when processing command line module system properties. 37 public class ModuleOptionsWarn { 38 39 public static void main(String[] args) throws Exception { 40 41 // Test that a warning is not issued for extraneous jdk.module properties. 42 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( 43 "-XX:+PrintWarnings", "-Djdk.module.ignored", "-version"); 44 OutputAnalyzer output = new OutputAnalyzer(pb.start()); 45 output.shouldNotContain("Ignoring system property option"); 46 output.shouldHaveExitValue(0); 47 48 // Test that a warning is issued for a reserved jdk.module property. 49 pb = ProcessTools.createJavaProcessBuilder( 50 "-XX:+PrintWarnings", "-Djdk.module.addmods", "-version"); 51 output = new OutputAnalyzer(pb.start()); 52 output.shouldContain("Ignoring system property option"); 53 output.shouldHaveExitValue(0); 54 55 // Test that a warning is issued for a reserved jdk.module property ending in '.'. 56 pb = ProcessTools.createJavaProcessBuilder( 57 "-XX:+PrintWarnings", "-Djdk.module.limitmods.", "-version"); 58 output = new OutputAnalyzer(pb.start()); 59 output.shouldContain("Ignoring system property option"); 60 output.shouldHaveExitValue(0); 61 62 // Test that a warning is issued for a reserved jdk.module property ending in '='. 63 pb = ProcessTools.createJavaProcessBuilder( 64 "-XX:+PrintWarnings", "-Djdk.module.addexports=", "-version"); 65 output = new OutputAnalyzer(pb.start()); 66 output.shouldContain("Ignoring system property option"); 67 output.shouldHaveExitValue(0); 68 69 // Test that a warning is issued for a reserved jdk.module property ending in ".stuff" 70 pb = ProcessTools.createJavaProcessBuilder( 71 "-XX:+PrintWarnings", "-Djdk.module.addreads.stuff", "-version"); 72 output = new OutputAnalyzer(pb.start()); 73 output.shouldContain("Ignoring system property option"); 74 output.shouldHaveExitValue(0); 75 76 // Test that a warning is issued for a reserved jdk.module property ending in "=stuff" 77 pb = ProcessTools.createJavaProcessBuilder( 78 "-XX:+PrintWarnings", "-Djdk.module.path=stuff", "-version"); 79 output = new OutputAnalyzer(pb.start()); 80 output.shouldContain("Ignoring system property option"); 81 output.shouldHaveExitValue(0); 82 83 // Test that a warning is issued for a reserved jdk.module property ending in ".=" 84 pb = ProcessTools.createJavaProcessBuilder( 85 "-XX:+PrintWarnings", "-Djdk.module.upgrade.path.=xx", "-version"); 86 output = new OutputAnalyzer(pb.start()); 87 output.shouldContain("Ignoring system property option"); 88 output.shouldHaveExitValue(0); 89 90 // Test that a warning is issued for a reserved jdk.module property ending in ".<num>" 91 pb = ProcessTools.createJavaProcessBuilder( 92 "-XX:+PrintWarnings", "-Djdk.module.patch.3=xx", "-version"); 93 output = new OutputAnalyzer(pb.start()); 94 output.shouldContain("Ignoring system property option"); 95 output.shouldHaveExitValue(0); 96 97 // Test that a warning can be suppressed for module related properties that get ignored. 98 pb = ProcessTools.createJavaProcessBuilder( 99 "-Djdk.module.addmods", "-XX:-PrintWarnings", "-version"); 100 output = new OutputAnalyzer(pb.start()); 101 output.shouldNotContain("Ignoring system property option"); 102 output.shouldHaveExitValue(0); 103 104 // Test that a warning is not issued for properties of the form "jdk.module.main" 105 pb = ProcessTools.createJavaProcessBuilder( 106 "-XX:+PrintWarnings", "-Djdk.module.main.ignored", "-version"); 107 output = new OutputAnalyzer(pb.start()); 108 output.shouldNotContain("Ignoring system property option"); 109 output.shouldHaveExitValue(0); 110 111 // Test that a warning is issued for module related properties specified using _JAVA_OPTIONS. 112 pb = ProcessTools.createJavaProcessBuilder("-XX:+PrintWarnings", "-version"); 113 Map<String, String> env = pb.environment(); 114 env.put("_JAVA_OPTIONS", "-Djdk.module.addreads"); 115 output = new OutputAnalyzer(pb.start()); 116 output.shouldContain("Ignoring system property option"); 117 output.shouldHaveExitValue(0); 118 } 119 }