Java tutorial
//package com.java2s; import java.util.HashMap; import java.util.Map; public class Main { public static <K, V> Map<K, V> copyNullSafeMutableHashMap(Map<? extends K, ? extends V> map) { if (map == null) throw new NullPointerException("map"); Map<K, V> result = new HashMap<K, V>(map); for (Map.Entry<K, V> entry : result.entrySet()) { if (entry.getKey() == null) throw new NullPointerException("entry.getKey()"); if (entry.getValue() == null) throw new NullPointerException("entry.getValue()"); } return result; } }