mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-17 01:24:33 +02:00
8162412: Ignore any System property specified as -Djdk.module that matches reserved module system properties
Change the checks for module related properties to look for specific properties, not just jdk.module Reviewed-by: coleenp, gziemski, ddmitriev
This commit is contained in:
parent
31d8fcc4f9
commit
0fd1f32873
2 changed files with 98 additions and 19 deletions
|
@ -163,26 +163,47 @@ static void logOption(const char* opt) {
|
||||||
|
|
||||||
bool needs_module_property_warning = false;
|
bool needs_module_property_warning = false;
|
||||||
|
|
||||||
#define MODULE_PROPERTY_PREFIX "jdk.module"
|
#define MODULE_PROPERTY_PREFIX "jdk.module."
|
||||||
#define MODULE_PROPERTY_PREFIX_LEN 10
|
#define MODULE_PROPERTY_PREFIX_LEN 11
|
||||||
#define MODULE_MAIN_PROPERTY "jdk.module.main"
|
#define ADDEXPORTS "addexports"
|
||||||
#define MODULE_MAIN_PROPERTY_LEN 15
|
#define ADDEXPORTS_LEN 10
|
||||||
|
#define ADDREADS "addreads"
|
||||||
|
#define ADDREADS_LEN 8
|
||||||
|
#define PATCH "patch"
|
||||||
|
#define PATCH_LEN 5
|
||||||
|
#define ADDMODS "addmods"
|
||||||
|
#define ADDMODS_LEN 7
|
||||||
|
#define LIMITMODS "limitmods"
|
||||||
|
#define LIMITMODS_LEN 9
|
||||||
|
#define PATH "path"
|
||||||
|
#define PATH_LEN 4
|
||||||
|
#define UPGRADE_PATH "upgrade.path"
|
||||||
|
#define UPGRADE_PATH_LEN 12
|
||||||
|
|
||||||
// Return TRUE if option matches property, or property=, or property..
|
// Return TRUE if option matches 'property', or 'property=', or 'property.'.
|
||||||
static bool matches_property_prefix(const char* option, const char* property, size_t len) {
|
static bool matches_property_suffix(const char* option, const char* property, size_t len) {
|
||||||
return (strncmp(option, property, len) == 0) &&
|
return ((strncmp(option, property, len) == 0) &&
|
||||||
(option[len] == '=' || option[len] == '.' || option[len] == '\0');
|
(option[len] == '=' || option[len] == '.' || option[len] == '\0'));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return true if the property is either "jdk.module" or starts with "jdk.module.",
|
// Return true if property starts with "jdk.module." and its ensuing chars match
|
||||||
// but does not start with "jdk.module.main".
|
// any of the reserved module properties.
|
||||||
// Return false if jdk.module.main because jdk.module.main and jdk.module.main.class
|
// property should be passed without the leading "-D".
|
||||||
// are valid non-internal system properties.
|
|
||||||
// "property" should be passed without the leading "-D".
|
|
||||||
bool Arguments::is_internal_module_property(const char* property) {
|
bool Arguments::is_internal_module_property(const char* property) {
|
||||||
assert((strncmp(property, "-D", 2) != 0), "Unexpected leading -D");
|
assert((strncmp(property, "-D", 2) != 0), "Unexpected leading -D");
|
||||||
return (matches_property_prefix(property, MODULE_PROPERTY_PREFIX, MODULE_PROPERTY_PREFIX_LEN) &&
|
if (strncmp(property, MODULE_PROPERTY_PREFIX, MODULE_PROPERTY_PREFIX_LEN) == 0) {
|
||||||
!matches_property_prefix(property, MODULE_MAIN_PROPERTY, MODULE_MAIN_PROPERTY_LEN));
|
const char* property_suffix = property + MODULE_PROPERTY_PREFIX_LEN;
|
||||||
|
if (matches_property_suffix(property_suffix, ADDEXPORTS, ADDEXPORTS_LEN) ||
|
||||||
|
matches_property_suffix(property_suffix, ADDREADS, ADDREADS_LEN) ||
|
||||||
|
matches_property_suffix(property_suffix, PATCH, PATCH_LEN) ||
|
||||||
|
matches_property_suffix(property_suffix, ADDMODS, ADDMODS_LEN) ||
|
||||||
|
matches_property_suffix(property_suffix, LIMITMODS, LIMITMODS_LEN) ||
|
||||||
|
matches_property_suffix(property_suffix, PATH, PATH_LEN) ||
|
||||||
|
matches_property_suffix(property_suffix, UPGRADE_PATH, UPGRADE_PATH_LEN)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Process java launcher properties.
|
// Process java launcher properties.
|
||||||
|
@ -4287,8 +4308,8 @@ jint Arguments::parse(const JavaVMInitArgs* initial_cmd_args) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (needs_module_property_warning) {
|
if (needs_module_property_warning) {
|
||||||
warning("Ignoring system property options whose names start with '-Djdk.module'."
|
warning("Ignoring system property options whose names match the '-Djdk.module.*'."
|
||||||
" They are reserved for internal use.");
|
" names that are reserved for internal use.");
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(_ALLBSD_SOURCE) || defined(AIX) // UseLargePages is not yet supported on BSD and AIX.
|
#if defined(_ALLBSD_SOURCE) || defined(AIX) // UseLargePages is not yet supported on BSD and AIX.
|
||||||
|
|
|
@ -29,6 +29,7 @@
|
||||||
* @library /test/lib
|
* @library /test/lib
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
import jdk.test.lib.process.OutputAnalyzer;
|
import jdk.test.lib.process.OutputAnalyzer;
|
||||||
import jdk.test.lib.process.ProcessTools;
|
import jdk.test.lib.process.ProcessTools;
|
||||||
|
|
||||||
|
@ -37,16 +38,65 @@ public class ModuleOptionsWarn {
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
|
|
||||||
// Test that a warning is issued for module related properties that get ignored.
|
// Test that a warning is not issued for extraneous jdk.module properties.
|
||||||
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
|
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
|
||||||
"-XX:+PrintWarnings", "-Djdk.module.ignored", "-version");
|
"-XX:+PrintWarnings", "-Djdk.module.ignored", "-version");
|
||||||
OutputAnalyzer output = new OutputAnalyzer(pb.start());
|
OutputAnalyzer output = new OutputAnalyzer(pb.start());
|
||||||
|
output.shouldNotContain("Ignoring system property option");
|
||||||
|
output.shouldHaveExitValue(0);
|
||||||
|
|
||||||
|
// Test that a warning is issued for a reserved jdk.module property.
|
||||||
|
pb = ProcessTools.createJavaProcessBuilder(
|
||||||
|
"-XX:+PrintWarnings", "-Djdk.module.addmods", "-version");
|
||||||
|
output = new OutputAnalyzer(pb.start());
|
||||||
|
output.shouldContain("Ignoring system property option");
|
||||||
|
output.shouldHaveExitValue(0);
|
||||||
|
|
||||||
|
// Test that a warning is issued for a reserved jdk.module property ending in '.'.
|
||||||
|
pb = ProcessTools.createJavaProcessBuilder(
|
||||||
|
"-XX:+PrintWarnings", "-Djdk.module.limitmods.", "-version");
|
||||||
|
output = new OutputAnalyzer(pb.start());
|
||||||
|
output.shouldContain("Ignoring system property option");
|
||||||
|
output.shouldHaveExitValue(0);
|
||||||
|
|
||||||
|
// Test that a warning is issued for a reserved jdk.module property ending in '='.
|
||||||
|
pb = ProcessTools.createJavaProcessBuilder(
|
||||||
|
"-XX:+PrintWarnings", "-Djdk.module.addexports=", "-version");
|
||||||
|
output = new OutputAnalyzer(pb.start());
|
||||||
|
output.shouldContain("Ignoring system property option");
|
||||||
|
output.shouldHaveExitValue(0);
|
||||||
|
|
||||||
|
// Test that a warning is issued for a reserved jdk.module property ending in ".stuff"
|
||||||
|
pb = ProcessTools.createJavaProcessBuilder(
|
||||||
|
"-XX:+PrintWarnings", "-Djdk.module.addreads.stuff", "-version");
|
||||||
|
output = new OutputAnalyzer(pb.start());
|
||||||
|
output.shouldContain("Ignoring system property option");
|
||||||
|
output.shouldHaveExitValue(0);
|
||||||
|
|
||||||
|
// Test that a warning is issued for a reserved jdk.module property ending in "=stuff"
|
||||||
|
pb = ProcessTools.createJavaProcessBuilder(
|
||||||
|
"-XX:+PrintWarnings", "-Djdk.module.path=stuff", "-version");
|
||||||
|
output = new OutputAnalyzer(pb.start());
|
||||||
|
output.shouldContain("Ignoring system property option");
|
||||||
|
output.shouldHaveExitValue(0);
|
||||||
|
|
||||||
|
// Test that a warning is issued for a reserved jdk.module property ending in ".="
|
||||||
|
pb = ProcessTools.createJavaProcessBuilder(
|
||||||
|
"-XX:+PrintWarnings", "-Djdk.module.upgrade.path.=xx", "-version");
|
||||||
|
output = new OutputAnalyzer(pb.start());
|
||||||
|
output.shouldContain("Ignoring system property option");
|
||||||
|
output.shouldHaveExitValue(0);
|
||||||
|
|
||||||
|
// Test that a warning is issued for a reserved jdk.module property ending in ".<num>"
|
||||||
|
pb = ProcessTools.createJavaProcessBuilder(
|
||||||
|
"-XX:+PrintWarnings", "-Djdk.module.patch.3=xx", "-version");
|
||||||
|
output = new OutputAnalyzer(pb.start());
|
||||||
output.shouldContain("Ignoring system property option");
|
output.shouldContain("Ignoring system property option");
|
||||||
output.shouldHaveExitValue(0);
|
output.shouldHaveExitValue(0);
|
||||||
|
|
||||||
// Test that a warning can be suppressed for module related properties that get ignored.
|
// Test that a warning can be suppressed for module related properties that get ignored.
|
||||||
pb = ProcessTools.createJavaProcessBuilder(
|
pb = ProcessTools.createJavaProcessBuilder(
|
||||||
"-Djdk.module.ignored", "-XX:-PrintWarnings", "-version");
|
"-Djdk.module.addmods", "-XX:-PrintWarnings", "-version");
|
||||||
output = new OutputAnalyzer(pb.start());
|
output = new OutputAnalyzer(pb.start());
|
||||||
output.shouldNotContain("Ignoring system property option");
|
output.shouldNotContain("Ignoring system property option");
|
||||||
output.shouldHaveExitValue(0);
|
output.shouldHaveExitValue(0);
|
||||||
|
@ -57,5 +107,13 @@ public class ModuleOptionsWarn {
|
||||||
output = new OutputAnalyzer(pb.start());
|
output = new OutputAnalyzer(pb.start());
|
||||||
output.shouldNotContain("Ignoring system property option");
|
output.shouldNotContain("Ignoring system property option");
|
||||||
output.shouldHaveExitValue(0);
|
output.shouldHaveExitValue(0);
|
||||||
|
|
||||||
|
// Test that a warning is issued for module related properties specified using _JAVA_OPTIONS.
|
||||||
|
pb = ProcessTools.createJavaProcessBuilder("-XX:+PrintWarnings", "-version");
|
||||||
|
Map<String, String> env = pb.environment();
|
||||||
|
env.put("_JAVA_OPTIONS", "-Djdk.module.addreads");
|
||||||
|
output = new OutputAnalyzer(pb.start());
|
||||||
|
output.shouldContain("Ignoring system property option");
|
||||||
|
output.shouldHaveExitValue(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue