public static <K, V> void validateNotNull(Map<? extends K, ? extends V> map) {
        checkNotNull(map, "map is null");

        boolean containsNullKey = false;
        boolean containsNullValue = false;
        // we catch possible NPE since the Map implementation could not support null values
        // TODO: is it possible to validate a map more efficiently without try-catch blocks?
        try {
            containsNullKey = map.containsKey(null);
        } catch (NullPointerException e) {
            // ignore if null key is not allowed for this map
            ignore(e);
        }
        try {
            containsNullValue = map.containsValue(null);
        } catch (NullPointerException e) {
            // ignore if null value is not allowed for this map
            ignore(e);
        }
        if (containsNullKey) {
            throw new NullPointerException(NULL_KEY_IS_NOT_ALLOWED);
        }
        if (containsNullValue) {
            throw new NullPointerException(NULL_VALUE_IS_NOT_ALLOWED);
        }
    }
public static < K , V > void validateNotNull ( Map < ? extends K , ? extends V > map ) { checkNotNull ( map , "map is null" ) ; boolean containsNullKey = false ; boolean containsNullValue = false ; try { containsNullKey = map . containsKey ( null ) ; } catch ( NullPointerException e ) { ignore ( e ) ; } try { containsNullValue = map . containsValue ( null ) ; } catch ( NullPointerException e ) { ignore ( e ) ; } if ( containsNullKey ) { throw new NullPointerException ( NULL_KEY_IS_NOT_ALLOWED ) ; } if ( containsNullValue ) { throw new NullPointerException ( NULL_VALUE_IS_NOT_ALLOWED ) ; } }
This validator ensures that no key or value is null in the provided map.

@param map the map to be validated.
@param <K> the type of key.
@param <V> the type of value.
@throws java.lang.NullPointerException if provided map contains a null key or value in the map.