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