< prev index next >

src/java.base/share/classes/java/lang/System.java

Print this page
rev 52881 : 8214971: Replace use of string.equals("") with isEmpty()


 953      * @see        #setProperty
 954      * @see        java.util.Properties
 955      * @see        java.lang.SecurityException
 956      * @see        java.lang.SecurityManager#checkPropertiesAccess()
 957      * @since 1.5
 958      */
 959     public static String clearProperty(String key) {
 960         checkKey(key);
 961         SecurityManager sm = getSecurityManager();
 962         if (sm != null) {
 963             sm.checkPermission(new PropertyPermission(key, "write"));
 964         }
 965 
 966         return (String) props.remove(key);
 967     }
 968 
 969     private static void checkKey(String key) {
 970         if (key == null) {
 971             throw new NullPointerException("key can't be null");
 972         }
 973         if (key.equals("")) {
 974             throw new IllegalArgumentException("key can't be empty");
 975         }
 976     }
 977 
 978     /**
 979      * Gets the value of the specified environment variable. An
 980      * environment variable is a system-dependent external named
 981      * value.
 982      *
 983      * <p>If a security manager exists, its
 984      * {@link SecurityManager#checkPermission checkPermission}
 985      * method is called with a
 986      * {@code {@link RuntimePermission}("getenv."+name)}
 987      * permission.  This may result in a {@link SecurityException}
 988      * being thrown.  If no exception is thrown the value of the
 989      * variable {@code name} is returned.
 990      *
 991      * <p><a id="EnvironmentVSSystemProperties"><i>System
 992      * properties</i> and <i>environment variables</i></a> are both
 993      * conceptually mappings between names and values.  Both




 953      * @see        #setProperty
 954      * @see        java.util.Properties
 955      * @see        java.lang.SecurityException
 956      * @see        java.lang.SecurityManager#checkPropertiesAccess()
 957      * @since 1.5
 958      */
 959     public static String clearProperty(String key) {
 960         checkKey(key);
 961         SecurityManager sm = getSecurityManager();
 962         if (sm != null) {
 963             sm.checkPermission(new PropertyPermission(key, "write"));
 964         }
 965 
 966         return (String) props.remove(key);
 967     }
 968 
 969     private static void checkKey(String key) {
 970         if (key == null) {
 971             throw new NullPointerException("key can't be null");
 972         }
 973         if (key.isEmpty()) {
 974             throw new IllegalArgumentException("key can't be empty");
 975         }
 976     }
 977 
 978     /**
 979      * Gets the value of the specified environment variable. An
 980      * environment variable is a system-dependent external named
 981      * value.
 982      *
 983      * <p>If a security manager exists, its
 984      * {@link SecurityManager#checkPermission checkPermission}
 985      * method is called with a
 986      * {@code {@link RuntimePermission}("getenv."+name)}
 987      * permission.  This may result in a {@link SecurityException}
 988      * being thrown.  If no exception is thrown the value of the
 989      * variable {@code name} is returned.
 990      *
 991      * <p><a id="EnvironmentVSSystemProperties"><i>System
 992      * properties</i> and <i>environment variables</i></a> are both
 993      * conceptually mappings between names and values.  Both


< prev index next >