Class JvmUtils


  • public class JvmUtils
    extends java.lang.Object
    • Constructor Summary

      Constructors 
      Constructor Description
      JvmUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void checkVMArgs​(java.lang.String vmArgs)
      Check that the VM args are valid and safe.
      static java.util.List<java.lang.String> dropMissingModules​(java.util.List<java.lang.String> vmArgs)
      Removes modules this JVM lacks from --add-modules: a missing one aborts JVM startup, while --add-exports/--add-opens to a missing module only warn.
      static java.lang.String findOnPath​(java.lang.String[] bins)
      Find a binary of the given binaries on PATH.
      private static java.util.Set<java.lang.String> getConfigJvmArgsWhitelist()  
      static java.lang.String getJavaWsBin()  
      (package private) static java.util.Map<java.lang.String,​java.util.Set<java.lang.String>> getPredefinedJavaModulesVMArgumentsMap()
      Defined in itw-modularjdk.args.
      private static java.lang.String[] getValidSecureProperties()
      https://docs.oracle.com/javase/8/docs/technotes/guides/javaws/developersguide/syntax.html#secure-property
      static java.lang.String[] getValidStartingJavaModuleVMArguments()
      https://docs.oracle.com/javase/9/tools/java.htm#JSWOR624 Java Module VM arguments specified by app developer in jnlp file.
      private static java.lang.String[] getValidStartingVMArguments()
      Returns an array containing the starts of valid (ie safe and supported) arguments for the JVM
      private static java.lang.String[] getValidVMArguments()
      Returns an array of valid (ie safe and supported) arguments for the JVM
      (package private) static boolean isSecurePropertyAValidJVMArg​(java.lang.String argument)
      Properties set in the JNLP file will normally be set by Web Start after the VM is started but before the application is invoked.
      (package private) static boolean isSystemModule​(java.lang.String name)  
      private static boolean isValidArgument​(java.lang.String argument)  
      private static boolean isValidConfigArgument​(java.lang.String argument)  
      static boolean isValidSecureProperty​(java.lang.String argument)
      A secure property is valid if it is in the whitelist or it begins with "jnlp." or "javaws."
      private static boolean isValidStartingArgument​(java.lang.String argument)  
      static boolean isValidStartingJavaModulesArgument​(java.lang.String argument)  
      static java.util.List<java.lang.String> mergeJavaModulesVMArgs​(java.util.List<java.lang.String> vmArgs)
      Combines PREDEFINED_JAVA_MODULES_VM_ARGUMENTS with the Java Module VM Args in the input vmargs.
      private static java.util.Set<java.lang.String> moduleArgs​(java.lang.String... args)  
      static java.util.List<java.lang.String> parseArguments​(java.lang.String args)  
      private static java.lang.String presentModules​(java.lang.String commaList)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • LOG

        private static final Logger LOG
      • VALID_VM_ARGUMENTS

        private static final java.util.Set<java.lang.String> VALID_VM_ARGUMENTS
      • VALID_STARTING_ARGUMENTS

        private static final java.util.List<java.lang.String> VALID_STARTING_ARGUMENTS
      • VALID_STARTING_JAVA_MODULES_ARGUMENTS

        private static final java.util.List<java.lang.String> VALID_STARTING_JAVA_MODULES_ARGUMENTS
      • VALID_SECURE_PROPERTIES

        private static final java.util.Set<java.lang.String> VALID_SECURE_PROPERTIES
      • WHITESPACE_REGEX

        private static final java.lang.String WHITESPACE_REGEX
        See Also:
        Constant Field Values
      • KEY_VALUE_SEPARATOR

        private static final java.lang.String KEY_VALUE_SEPARATOR
        See Also:
        Constant Field Values
      • configJvmArgsWhitelist

        private static java.util.Set<java.lang.String> configJvmArgsWhitelist
    • Constructor Detail

      • JvmUtils

        public JvmUtils()
    • Method Detail

      • checkVMArgs

        public static void checkVMArgs​(java.lang.String vmArgs)
                                throws java.lang.IllegalArgumentException
        Check that the VM args are valid and safe.

        Based on http://java.sun.com/javase/6/docs/technotes/guides/javaws/developersguide/syntax.html

        Parameters:
        vmArgs - a string containing the args
        Throws:
        java.lang.IllegalArgumentException - if the VM arguments are invalid or dangerous
      • isValidArgument

        private static boolean isValidArgument​(java.lang.String argument)
      • isSecurePropertyAValidJVMArg

        static boolean isSecurePropertyAValidJVMArg​(java.lang.String argument)
        Properties set in the JNLP file will normally be set by Web Start after the VM is started but before the application is invoked. Some properties are considered "secure" properties and can be passed as -Dkey=value arguments on the java invocation command line.
      • isValidStartingArgument

        private static boolean isValidStartingArgument​(java.lang.String argument)
      • isValidStartingJavaModulesArgument

        public static boolean isValidStartingJavaModulesArgument​(java.lang.String argument)
      • isValidSecureProperty

        public static boolean isValidSecureProperty​(java.lang.String argument)
        A secure property is valid if it is in the whitelist or it begins with "jnlp." or "javaws."
        See Also:
        Java 8 Spec
      • getConfigJvmArgsWhitelist

        private static java.util.Set<java.lang.String> getConfigJvmArgsWhitelist()
      • isValidConfigArgument

        private static boolean isValidConfigArgument​(java.lang.String argument)
      • getValidVMArguments

        private static java.lang.String[] getValidVMArguments()
        Returns an array of valid (ie safe and supported) arguments for the JVM

        Based on https://docs.oracle.com/javase/8/docs/technotes/guides/javaws/developersguide/syntax.html#secure-property

      • getValidStartingVMArguments

        private static java.lang.String[] getValidStartingVMArguments()
        Returns an array containing the starts of valid (ie safe and supported) arguments for the JVM

        Based on https://docs.oracle.com/javase/8/docs/technotes/guides/javaws/developersguide/syntax.html#secure-property https://docs.oracle.com/en/java/javase/21/docs/specs/man/java.html

      • getValidSecureProperties

        private static java.lang.String[] getValidSecureProperties()
        https://docs.oracle.com/javase/8/docs/technotes/guides/javaws/developersguide/syntax.html#secure-property

        Properties set in the JNLP file will normally be set by Web Start after the VM is started but before the application is invoked. These properties are considered "secure" properties and can be passed as -Dkey=value arguments on the java invocation command line. The following properties are predefined secure properties and will be passed to the VM in this way.

      • getJavaWsBin

        public static java.lang.String getJavaWsBin()
        Returns:
        the javaws binary.
      • findOnPath

        public static java.lang.String findOnPath​(java.lang.String[] bins)
        Find a binary of the given binaries on PATH.
        Parameters:
        bins - list of binaries to look for
        Returns:
        the absolute path to the first binary found
      • getValidStartingJavaModuleVMArguments

        public static java.lang.String[] getValidStartingJavaModuleVMArguments()
        https://docs.oracle.com/javase/9/tools/java.htm#JSWOR624 Java Module VM arguments specified by app developer in jnlp file. ITW adds its own set of jvm args either through getPredefinedJavaModulesVMArgumentsMap() or the itw-modularjdk.args file. These are required for the execution of ITW.

        Note: --module-path is not accepted by ITW as it would circumvent the classloader and security.

      • getPredefinedJavaModulesVMArgumentsMap

        static java.util.Map<java.lang.String,​java.util.Set<java.lang.String>> getPredefinedJavaModulesVMArgumentsMap()
        Defined in itw-modularjdk.args. Required for running ITW with jdk 9 or higher
      • moduleArgs

        private static java.util.Set<java.lang.String> moduleArgs​(java.lang.String... args)
      • dropMissingModules

        public static java.util.List<java.lang.String> dropMissingModules​(java.util.List<java.lang.String> vmArgs)
        Removes modules this JVM lacks from --add-modules: a missing one aborts JVM startup, while --add-exports/--add-opens to a missing module only warn. E.g. JOSM's JNLP asks for javafx.* which plain OpenJDK does not have.
      • presentModules

        private static java.lang.String presentModules​(java.lang.String commaList)
      • isSystemModule

        static boolean isSystemModule​(java.lang.String name)
      • mergeJavaModulesVMArgs

        public static java.util.List<java.lang.String> mergeJavaModulesVMArgs​(java.util.List<java.lang.String> vmArgs)
        Combines PREDEFINED_JAVA_MODULES_VM_ARGUMENTS with the Java Module VM Args in the input vmargs. Does not check legality of args, this is done by checkVMArgs(String)check
      • parseArguments

        public static java.util.List<java.lang.String> parseArguments​(java.lang.String args)
                                                               throws ParseException
        Throws:
        ParseException