< prev index next >

src/jdk/nashorn/internal/runtime/options/Options.java

Print this page

        

@@ -134,23 +134,25 @@
     @Override
     public String toString() {
         return options.toString();
     }
 
+    private static void checkPropertyName(final String name) {
+        if (! Objects.requireNonNull(name).startsWith("nashorn.")) {
+            throw new IllegalArgumentException(name);
+        }
+    }
+
     /**
      * Convenience function for getting system properties in a safe way
 
      * @param name of boolean property
      * @param defValue default value of boolean property
      * @return true if set to true, default value if unset or set to false
      */
     public static boolean getBooleanProperty(final String name, final Boolean defValue) {
-        Objects.requireNonNull(name);
-        if (!name.startsWith("nashorn.")) {
-            throw new IllegalArgumentException(name);
-        }
-
+        checkPropertyName(name);
         return AccessController.doPrivileged(
                 new PrivilegedAction<Boolean>() {
                     @Override
                     public Boolean run() {
                         try {

@@ -183,15 +185,11 @@
      * @param name of string property
      * @param defValue the default value if unset
      * @return string property if set or default value
      */
     public static String getStringProperty(final String name, final String defValue) {
-        Objects.requireNonNull(name);
-        if (! name.startsWith("nashorn.")) {
-            throw new IllegalArgumentException(name);
-        }
-
+        checkPropertyName(name);
         return AccessController.doPrivileged(
                 new PrivilegedAction<String>() {
                     @Override
                     public String run() {
                         try {

@@ -210,15 +208,11 @@
      * @param name of integer property
      * @param defValue the default value if unset
      * @return integer property if set or default value
      */
     public static int getIntProperty(final String name, final int defValue) {
-        Objects.requireNonNull(name);
-        if (! name.startsWith("nashorn.")) {
-            throw new IllegalArgumentException(name);
-        }
-
+        checkPropertyName(name);
         return AccessController.doPrivileged(
                 new PrivilegedAction<Integer>() {
                     @Override
                     public Integer run() {
                         try {
< prev index next >