Skip to content

Commit

Permalink
8287924: Avoid redundant HashMap.containsKey call in EnvHelp.mapToHas…
Browse files Browse the repository at this point in the history
…htable

Reviewed-by: sspitsyn, cjplummer
  • Loading branch information
Andrey Turbanov committed Jun 9, 2022
1 parent d482d7f commit 900d967
Showing 1 changed file with 3 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@
import javax.management.remote.JMXConnectorServerFactory;
import com.sun.jmx.mbeanserver.GetPropertyAction;
import com.sun.jmx.remote.security.NotificationAccessController;
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorServer;

public class EnvHelp {

Expand Down Expand Up @@ -733,11 +731,11 @@ else if (stringBoolean.equalsIgnoreCase("false"))
* it removes all the 'null' values from the map.
*/
public static <K, V> Hashtable<K, V> mapToHashtable(Map<K, V> map) {
HashMap<K, V> m = new HashMap<K, V>(map);
if (m.containsKey(null)) m.remove(null);
HashMap<K, V> m = new HashMap<>(map);
m.remove(null);
for (Iterator<?> i = m.values().iterator(); i.hasNext(); )
if (i.next() == null) i.remove();
return new Hashtable<K, V>(m);
return new Hashtable<>(m);
}

/**
Expand Down

1 comment on commit 900d967

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.