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 8136930 27 * @summary Test that the VM ignores explicitly specified module internal properties. 28 * @modules java.base/jdk.internal.misc 29 * @library /testlibrary 30 */ 31 32 import jdk.test.lib.*; 33 34 // Test that the VM ignores module related properties such as "jdk.module.addmods" 35 // and jdk.module.addreads.0" that can only be set using module options. 36 public class IgnoreModulePropertiesTest { 37 38 // Test that the specified property and its value are ignored. If the VM accepted 39 // the property and value then an exception would be thrown because the value is 40 // bogus for that property. But, since the property is ignored no exception is 41 // thrown. 42 public static void testProperty(String prop, String value) throws Exception { 43 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( 44 "-D" + prop + "=" + value, "-version"); 45 OutputAnalyzer output = new OutputAnalyzer(pb.start()); 46 output.shouldContain("java version "); 47 output.shouldHaveExitValue(0); 48 49 // Ensure that the property and its value aren't available. 50 if (System.getProperty(prop) != null) { 51 throw new RuntimeException( 52 "Unexpected non-null value for property " + prop); 53 } 54 } 55 56 // For options of the form "option=value", check that an exception gets thrown for 57 // the illegal value and then check that its corresponding property is handled 58 // correctly. 59 public static void testOption(String option, String value, 60 String prop, String result) throws Exception { 61 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( 62 option + "=" + value, "-version"); 63 OutputAnalyzer output = new OutputAnalyzer(pb.start()); 64 output.shouldContain(result); 65 testProperty(prop, value); 66 } 67 68 public static void main(String[] args) throws Exception { 69 testOption("--add-modules", "java.sqlx", "jdk.module.addmods", "java.lang.module.ResolutionException"); 70 testOption("--limit-modules", "java.sqlx", "jdk.module.limitmods", "java.lang.module.ResolutionException"); 71 testOption("--add-reads", "xyzz=yyzd", "jdk.module.addreads.0", "java.lang.RuntimeException"); 72 testOption("--add-exports", "java.base/xyzz=yyzd", "jdk.module.addexports.0", "java.lang.RuntimeException"); 73 testOption("--patch-module", "=d", "jdk.module.patch.0", "IllegalArgumentException"); 74 } 75 }