private static void validateProperties()

in sdk/appcenter-analytics/src/main/java/com/microsoft/appcenter/analytics/channel/AnalyticsValidator.java [155:213]


    private static void validateProperties(List<TypedProperty> properties) {
        if (properties == null) {
            return;
        }
        int count = 0;
        boolean maxCountReached = false;
        String message;
        for (ListIterator<TypedProperty> iterator = properties.listIterator(); iterator.hasNext(); ) {
            boolean copyNeededOnModification = true;
            TypedProperty property = iterator.next();
            String key = property.getName();
            if (count >= MAX_PROPERTY_COUNT) {
                if (!maxCountReached) {
                    message = String.format("Typed properties cannot contain more than %s items. Skipping other properties.", MAX_PROPERTY_COUNT);
                    AppCenterLog.warn(LOG_TAG, message);
                    maxCountReached = true;
                }
                iterator.remove();
                continue;
            }
            if (key == null || key.isEmpty()) {
                AppCenterLog.warn(LOG_TAG, "A typed property key cannot be null or empty. Property will be skipped.");
                iterator.remove();
                continue;
            }
            if (key.length() > MAX_PROPERTY_ITEM_LENGTH) {
                message = String.format("Typed property '%s' : property key length cannot be longer than %s characters. Property key will be truncated.", key, MAX_PROPERTY_ITEM_LENGTH);
                AppCenterLog.warn(LOG_TAG, message);
                key = key.substring(0, MAX_PROPERTY_ITEM_LENGTH);
                property = copyProperty(property, key);
                iterator.set(property);
                copyNeededOnModification = false;
            }
            if (property instanceof StringTypedProperty) {
                StringTypedProperty stringTypedProperty = (StringTypedProperty) property;
                String value = stringTypedProperty.getValue();
                if (value == null) {
                    message = String.format("Typed property '%s' : property value cannot be null. Property '%s' will be skipped.", key, key);
                    AppCenterLog.warn(LOG_TAG, message);
                    iterator.remove();
                    continue;
                }
                if (value.length() > MAX_PROPERTY_ITEM_LENGTH) {
                    message = String.format("A String property '%s' : property value cannot be longer than %s characters. Property value will be truncated.", key, MAX_PROPERTY_ITEM_LENGTH);
                    AppCenterLog.warn(LOG_TAG, message);
                    value = value.substring(0, MAX_PROPERTY_ITEM_LENGTH);
                    if (copyNeededOnModification) {
                        stringTypedProperty = new StringTypedProperty();
                        stringTypedProperty.setName(key);
                        stringTypedProperty.setValue(value);
                        iterator.set(stringTypedProperty);
                    } else {
                        stringTypedProperty.setValue(value);
                    }
                }
            }
            count++;
        }
    }