ErrorLogHelper { public static Map<String, String> validateProperties(Map<String, String> properties, String logType) { if (properties == null) { return null; } String message; Map<String, String> result = new HashMap<>(); for (Map.Entry<String, String> property : properties.entrySet()) { String key = property.getKey(); String value = property.getValue(); if (result.size() >= MAX_PROPERTY_COUNT) { message = String.format("%s : properties cannot contain more than %s items. Skipping other properties.", logType, MAX_PROPERTY_COUNT); AppCenterLog.warn(Crashes.LOG_TAG, message); break; } if (key == null || key.isEmpty()) { message = String.format("%s : a property key cannot be null or empty. Property will be skipped.", logType); AppCenterLog.warn(Crashes.LOG_TAG, message); continue; } if (value == null) { message = String.format("%s : property '%s' : property value cannot be null. Property '%s' will be skipped.", logType, key, key); AppCenterLog.warn(Crashes.LOG_TAG, message); continue; } if (key.length() > MAX_PROPERTY_ITEM_LENGTH) { message = String.format("%s : property '%s' : property key length cannot be longer than %s characters. Property key will be truncated.", logType, key, MAX_PROPERTY_ITEM_LENGTH); AppCenterLog.warn(Crashes.LOG_TAG, message); key = key.substring(0, MAX_PROPERTY_ITEM_LENGTH); } if (value.length() > MAX_PROPERTY_ITEM_LENGTH) { message = String.format("%s : property '%s' : property value cannot be longer than %s characters. Property value will be truncated.", logType, key, MAX_PROPERTY_ITEM_LENGTH); AppCenterLog.warn(Crashes.LOG_TAG, message); value = value.substring(0, MAX_PROPERTY_ITEM_LENGTH); } result.put(key, value); } return result; }  @NonNull static ManagedErrorLog createErrorLog(@NonNull Context context, @NonNull final java.lang.Thread thread, @NonNull final Throwable throwable, @NonNull final Map<java.lang.Thread, StackTraceElement[]> allStackTraces, final long initializeTimestamp); @NonNull static ManagedErrorLog createErrorLog(@NonNull Context context, @NonNull final java.lang.Thread thread, @NonNull final Exception exception, @NonNull final Map<java.lang.Thread, StackTraceElement[]> allStackTraces, final long initializeTimestamp, boolean fatal); @NonNull static synchronized File getErrorStorageDirectory(); @NonNull static synchronized File getNewMinidumpDirectory(); @NonNull static synchronized File getNewMinidumpSubfolder(); @NonNull static synchronized File getNewMinidumpSubfolderWithContextData(Context context); @NonNull static synchronized File getPendingMinidumpDirectory(); @NonNull static File[] getStoredErrorLogFiles(); @NonNull static File[] getNewMinidumpFiles(); @Nullable static Device getStoredDeviceInfo(File logFolder); static void removeStaleMinidumpSubfolders(); static void removeMinidumpFolder(); @Nullable static File getLastErrorLogFile(); @Nullable static File getStoredThrowableFile(@NonNull UUID id); static void removeStoredThrowableFile(@NonNull UUID id); static void removeStoredErrorLogFile(@NonNull UUID id); @NonNull static ErrorReport getErrorReportFromErrorLog(@NonNull ManagedErrorLog log, String stackTrace); @NonNull static Exception getModelExceptionFromThrowable(@NonNull Throwable t); static Map<String, String> validateProperties(Map<String, String> properties, String logType); static void cleanPendingMinidumps(); @NonNull static UUID parseLogFolderUuid(File logFolder); @VisibleForTesting static void clearStaticState(); static final String DEVICE_INFO_FILE; static final String ERROR_LOG_FILE_EXTENSION; static final String THROWABLE_FILE_EXTENSION; @VisibleForTesting
    static final int FRAME_LIMIT; static final int MAX_PROPERTY_ITEM_LENGTH; static final String MINIDUMP_FILE_EXTENSION; }
@Test public void validateProperties() { String logType = "HandledError"; HashMap<String, String> properties = new HashMap<String, String>() {{ put(null, null); put("", null); put(generateString(ErrorLogHelper.MAX_PROPERTY_ITEM_LENGTH + 1, '*'), null); put("1", null); }}; assertEquals(0, ErrorLogHelper.validateProperties(properties, logType).size()); properties = new HashMap<String, String>() {{ for (int i = 0; i < 30; i++) { put("valid" + i, "valid"); } }}; assertEquals(20, ErrorLogHelper.validateProperties(properties, logType).size()); final String longerMapItem = generateString(ErrorLogHelper.MAX_PROPERTY_ITEM_LENGTH + 1, '*'); properties = new HashMap<String, String>() {{ put(longerMapItem, longerMapItem); }}; Map<String, String> actualProperties = ErrorLogHelper.validateProperties(properties, logType); String truncatedMapItem = generateString(ErrorLogHelper.MAX_PROPERTY_ITEM_LENGTH, '*'); assertEquals(1, actualProperties.size()); assertEquals(truncatedMapItem, actualProperties.get(truncatedMapItem)); }