From 2562fb13f59fe7682dec88d59da43b2bacac8787 Mon Sep 17 00:00:00 2001 From: Arif Burak Demiray <57103426+arifBurakDemiray@users.noreply.github.com> Date: Tue, 16 Jan 2024 13:59:10 +0000 Subject: [PATCH] [Java] Fixing codacy - ConcurrentHashMap (#221) * feat: concurrent hash map * fix: codacy * fix: codacy * fix: revert split up * feat: revert transport * fix: rever change * fix: revert splitted --- .../src/main/java/ly/count/sdk/java/Config.java | 4 ++-- .../java/ly/count/sdk/java/internal/CrashImpl.java | 3 ++- .../java/ly/count/sdk/java/internal/Device.java | 8 ++++---- .../count/sdk/java/internal/ModuleBackendMode.java | 7 ++++--- .../sdk/java/internal/ModuleDeviceIdCore.java | 4 ++-- .../ly/count/sdk/java/internal/ModuleFeedback.java | 4 ++-- .../java/ly/count/sdk/java/internal/Params.java | 4 ++-- .../java/ly/count/sdk/java/internal/SDKCore.java | 6 +++--- .../java/ly/count/sdk/java/internal/Utils.java | 4 ++-- .../ly/count/sdk/java/internal/ConfigTests.java | 4 ++-- .../ly/count/sdk/java/internal/DeviceTests.java | 7 +++---- .../ly/count/sdk/java/internal/EventImplTests.java | 13 +++++++------ .../sdk/java/internal/MigrationHelperTests.java | 12 ++++++------ .../count/sdk/java/internal/ModuleEventsTests.java | 14 +++++++------- .../sdk/java/internal/ModuleFeedbackTests.java | 11 ++++++----- .../java/ly/count/sdk/java/internal/TestUtils.java | 11 +++++------ .../count/sdk/java/internal/TimedEventsTests.java | 6 +++--- .../ly/count/sdk/java/internal/UtilsTests.java | 5 +++-- 18 files changed, 65 insertions(+), 62 deletions(-) diff --git a/sdk-java/src/main/java/ly/count/sdk/java/Config.java b/sdk-java/src/main/java/ly/count/sdk/java/Config.java index 0bee67fce..93836f3f2 100644 --- a/sdk-java/src/main/java/ly/count/sdk/java/Config.java +++ b/sdk-java/src/main/java/ly/count/sdk/java/Config.java @@ -4,12 +4,12 @@ import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; -import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; import ly.count.sdk.java.internal.CoreFeature; import ly.count.sdk.java.internal.Log; import ly.count.sdk.java.internal.LogCallback; @@ -214,7 +214,7 @@ public String toString() { */ protected boolean enableBackendMode = false; - protected final Map metricOverride = new HashMap<>(); + protected final Map metricOverride = new ConcurrentHashMap<>(); /** * Salt string for parameter tampering protection diff --git a/sdk-java/src/main/java/ly/count/sdk/java/internal/CrashImpl.java b/sdk-java/src/main/java/ly/count/sdk/java/internal/CrashImpl.java index 8abab68ec..72e6003ec 100644 --- a/sdk-java/src/main/java/ly/count/sdk/java/internal/CrashImpl.java +++ b/sdk-java/src/main/java/ly/count/sdk/java/internal/CrashImpl.java @@ -8,6 +8,7 @@ import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; import ly.count.sdk.java.Crash; import org.json.JSONException; import org.json.JSONObject; @@ -150,7 +151,7 @@ public Map getSegments() { return null; } JSONObject object = this.data.getJSONObject("_custom"); - Map map = new HashMap<>(); + Map map = new ConcurrentHashMap<>(); Iterator iterator = object.keys(); while (iterator.hasNext()) { String key = iterator.next(); diff --git a/sdk-java/src/main/java/ly/count/sdk/java/internal/Device.java b/sdk-java/src/main/java/ly/count/sdk/java/internal/Device.java index bb5c9e0e2..7746a72a5 100644 --- a/sdk-java/src/main/java/ly/count/sdk/java/internal/Device.java +++ b/sdk-java/src/main/java/ly/count/sdk/java/internal/Device.java @@ -1,15 +1,15 @@ package ly.count.sdk.java.internal; import com.sun.management.OperatingSystemMXBean; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; import java.io.File; import java.lang.management.ManagementFactory; import java.util.Date; -import java.util.HashMap; import java.util.Locale; import java.util.Map; import java.util.TimeZone; +import java.util.concurrent.ConcurrentHashMap; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; /** * Class encapsulating most of device-specific logic: metrics, info, etc. @@ -31,7 +31,7 @@ public class Device { private Log L; - private final Map metricOverride = new HashMap<>(); + private final Map metricOverride = new ConcurrentHashMap<>(); protected Device() { dev = this; diff --git a/sdk-java/src/main/java/ly/count/sdk/java/internal/ModuleBackendMode.java b/sdk-java/src/main/java/ly/count/sdk/java/internal/ModuleBackendMode.java index 53bac5a7a..6d95307f7 100644 --- a/sdk-java/src/main/java/ly/count/sdk/java/internal/ModuleBackendMode.java +++ b/sdk-java/src/main/java/ly/count/sdk/java/internal/ModuleBackendMode.java @@ -8,6 +8,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; import org.json.JSONArray; import org.json.JSONObject; @@ -21,7 +22,7 @@ public class ModuleBackendMode extends ModuleBase { protected boolean disabledModule = false; protected int eventQSize = 0; - protected final Map eventQueues = new HashMap<>(); + protected final Map eventQueues = new ConcurrentHashMap<>(); final String[] userPredefinedKeys = { "name", "username", "email", "organization", "phone", "gender", "byear" }; @@ -181,8 +182,8 @@ private void recordUserPropertiesInternal(String deviceID, Map u removeInvalidDataFromSegments(userProperties); - Map userDetail = new HashMap<>(); - Map customDetail = new HashMap<>(); + Map userDetail = new ConcurrentHashMap<>(); + Map customDetail = new ConcurrentHashMap<>(); for (Map.Entry item : userProperties.entrySet()) { if (Arrays.stream(userPredefinedKeys).anyMatch(item.getKey()::equalsIgnoreCase)) { userDetail.put(item.getKey(), item.getValue()); diff --git a/sdk-java/src/main/java/ly/count/sdk/java/internal/ModuleDeviceIdCore.java b/sdk-java/src/main/java/ly/count/sdk/java/internal/ModuleDeviceIdCore.java index e2923eeae..dbc410e1d 100644 --- a/sdk-java/src/main/java/ly/count/sdk/java/internal/ModuleDeviceIdCore.java +++ b/sdk-java/src/main/java/ly/count/sdk/java/internal/ModuleDeviceIdCore.java @@ -1,8 +1,8 @@ package ly.count.sdk.java.internal; -import java.util.HashMap; import java.util.Map; import java.util.UUID; +import java.util.concurrent.ConcurrentHashMap; import ly.count.sdk.java.Config; import ly.count.sdk.java.Countly; @@ -44,7 +44,7 @@ public String generate(InternalConfig config) { } } - private static final Map generators = new HashMap<>(); + private static final Map generators = new ConcurrentHashMap<>(); protected DeviceId deviceIdInterface; diff --git a/sdk-java/src/main/java/ly/count/sdk/java/internal/ModuleFeedback.java b/sdk-java/src/main/java/ly/count/sdk/java/internal/ModuleFeedback.java index a0ee1da9d..c8659ac75 100644 --- a/sdk-java/src/main/java/ly/count/sdk/java/internal/ModuleFeedback.java +++ b/sdk-java/src/main/java/ly/count/sdk/java/internal/ModuleFeedback.java @@ -1,10 +1,10 @@ package ly.count.sdk.java.internal; import java.util.ArrayList; -import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; import javax.annotation.Nullable; import ly.count.sdk.java.Countly; import org.json.JSONArray; @@ -243,7 +243,7 @@ private void reportFeedbackWidgetManuallyInternal(CountlyFeedbackWidget widgetIn } } - Map segm = new HashMap<>(); + Map segm = new ConcurrentHashMap<>(); segm.put("platform", internalConfig.getSdkPlatform()); segm.put("app_version", cachedAppVersion); segm.put("widget_id", widgetInfo.widgetId); diff --git a/sdk-java/src/main/java/ly/count/sdk/java/internal/Params.java b/sdk-java/src/main/java/ly/count/sdk/java/internal/Params.java index 5fd95ec18..356e5006f 100644 --- a/sdk-java/src/main/java/ly/count/sdk/java/internal/Params.java +++ b/sdk-java/src/main/java/ly/count/sdk/java/internal/Params.java @@ -3,9 +3,9 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; -import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; import org.json.JSONException; import org.json.JSONObject; @@ -230,7 +230,7 @@ public String remove(final String key) { * @return map of the Params object */ public Map map() { - Map map = new HashMap<>(); + Map map = new ConcurrentHashMap<>(); List pairs = new ArrayList<>(Arrays.asList(params.toString().split("&"))); for (String pair : pairs) { String[] comps = pair.split("="); diff --git a/sdk-java/src/main/java/ly/count/sdk/java/internal/SDKCore.java b/sdk-java/src/main/java/ly/count/sdk/java/internal/SDKCore.java index 259cfb4a4..0991a7cfd 100644 --- a/sdk-java/src/main/java/ly/count/sdk/java/internal/SDKCore.java +++ b/sdk-java/src/main/java/ly/count/sdk/java/internal/SDKCore.java @@ -2,11 +2,11 @@ import java.util.ArrayDeque; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Queue; import java.util.TreeMap; +import java.util.concurrent.ConcurrentHashMap; import javax.annotation.Nullable; import ly.count.sdk.java.Config; @@ -74,7 +74,7 @@ protected static void registerDefaultModuleMappings() { /** * Selected by config map of module mappings */ - private static final Map> moduleMappings = new HashMap<>(); + private static final Map> moduleMappings = new ConcurrentHashMap<>(); protected static void registerModuleMapping(int feature, Class cls) { if (cls != null) { @@ -427,7 +427,7 @@ public void init(final InternalConfig givenConfig) { //setup and perform migrations MigrationHelper migrationHelper = new MigrationHelper(L); migrationHelper.setupMigrations(config.storageProvider); - Map migrationParams = new HashMap<>(); + Map migrationParams = new ConcurrentHashMap<>(); migrationParams.put("sdk_path", config.getSdkStorageRootDirectory()); migrationHelper.applyMigrations(migrationParams); diff --git a/sdk-java/src/main/java/ly/count/sdk/java/internal/Utils.java b/sdk-java/src/main/java/ly/count/sdk/java/internal/Utils.java index 1195edadd..e8c11b6b4 100644 --- a/sdk-java/src/main/java/ly/count/sdk/java/internal/Utils.java +++ b/sdk-java/src/main/java/ly/count/sdk/java/internal/Utils.java @@ -17,10 +17,10 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; -import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; /** * Utility class @@ -269,7 +269,7 @@ public static Map fixSegmentKeysAndValues(final int keyLength, f return segments; } - Map segmentation = new HashMap<>(); + Map segmentation = new ConcurrentHashMap<>(); for (Map.Entry entry : segments.entrySet()) { String k = entry.getKey(); diff --git a/sdk-java/src/test/java/ly/count/sdk/java/internal/ConfigTests.java b/sdk-java/src/test/java/ly/count/sdk/java/internal/ConfigTests.java index ba0f25ebb..2832b92ff 100644 --- a/sdk-java/src/test/java/ly/count/sdk/java/internal/ConfigTests.java +++ b/sdk-java/src/test/java/ly/count/sdk/java/internal/ConfigTests.java @@ -1,8 +1,8 @@ package ly.count.sdk.java.internal; import java.net.URL; -import java.util.HashMap; import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; import ly.count.sdk.java.Config; import org.junit.Assert; import org.junit.Test; @@ -126,7 +126,7 @@ public void metricOverride() { Map initialVals = internalConfig.getMetricOverride(); Assert.assertEquals(0, initialVals.size()); - Map newVals = new HashMap<>(); + Map newVals = new ConcurrentHashMap<>(); newVals.put("a", "1"); newVals.put("b", "2"); diff --git a/sdk-java/src/test/java/ly/count/sdk/java/internal/DeviceTests.java b/sdk-java/src/test/java/ly/count/sdk/java/internal/DeviceTests.java index dca75b431..72be03fba 100644 --- a/sdk-java/src/test/java/ly/count/sdk/java/internal/DeviceTests.java +++ b/sdk-java/src/test/java/ly/count/sdk/java/internal/DeviceTests.java @@ -1,10 +1,9 @@ package ly.count.sdk.java.internal; -import org.json.JSONObject; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; import org.junit.Assert; import org.junit.Test; -import java.util.HashMap; -import java.util.Map; public class DeviceTests { @@ -13,7 +12,7 @@ public class DeviceTests { */ @Test public void metricOverride_1() { - Map newVals = new HashMap<>(); + Map newVals = new ConcurrentHashMap<>(); newVals.put("a12345", "1qwer"); newVals.put("b5678", "2sdfg"); diff --git a/sdk-java/src/test/java/ly/count/sdk/java/internal/EventImplTests.java b/sdk-java/src/test/java/ly/count/sdk/java/internal/EventImplTests.java index 23644ecc7..c8225d820 100644 --- a/sdk-java/src/test/java/ly/count/sdk/java/internal/EventImplTests.java +++ b/sdk-java/src/test/java/ly/count/sdk/java/internal/EventImplTests.java @@ -3,6 +3,7 @@ import java.math.BigDecimal; import java.util.HashMap; import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; import org.json.JSONObject; import org.junit.Assert; import org.junit.Test; @@ -110,7 +111,7 @@ public void recorderCalledAfterRecord() { Assert.assertEquals(true, eventImpl1.getSegment("test")); }, "test_event", L); - Map segmentation = new HashMap<>(); + Map segmentation = new ConcurrentHashMap<>(); segmentation.put("test", true); event.count = 5; @@ -130,7 +131,7 @@ public void validateToJson() { EventImpl event = new EventImpl((event1) -> { }, "test_buy_event", L); - Map segmentation = new HashMap<>(); + Map segmentation = new ConcurrentHashMap<>(); segmentation.put("valid", false); event.duration = 34.0; @@ -161,7 +162,7 @@ public void validateFromJson() { EventImpl event = new EventImpl((event1) -> { }, "test_sell_event", L); - Map segmentation = new HashMap<>(); + Map segmentation = new ConcurrentHashMap<>(); segmentation.put("sold", true); event.count = 3; @@ -214,7 +215,7 @@ public void validateFromJson_toJson_segmentation() { segmentation.put("divisor", 0.2f); event.segmentation = segmentation; - Map expectedSegmentation = new HashMap<>(); + Map expectedSegmentation = new ConcurrentHashMap<>(); expectedSegmentation.put("sold", true); expectedSegmentation.put("price", BigDecimal.valueOf(9.43)); expectedSegmentation.put("quantity", 3); @@ -242,7 +243,7 @@ public void testGetters() { EventImpl event = new EventImpl((event1) -> { }, "test_getter_event", L); - Map segmentation = new HashMap<>(); + Map segmentation = new ConcurrentHashMap<>(); segmentation.put("get_func", 90); event.count = 47; @@ -270,7 +271,7 @@ public void testSetters() { event.setDuration(78); event.setSum(46); - Map segmentation = new HashMap<>(); + Map segmentation = new ConcurrentHashMap<>(); segmentation.put("donated_amount", "37656387"); event.setSegmentation(segmentation); diff --git a/sdk-java/src/test/java/ly/count/sdk/java/internal/MigrationHelperTests.java b/sdk-java/src/test/java/ly/count/sdk/java/internal/MigrationHelperTests.java index 6487cb4fb..419a6edfc 100644 --- a/sdk-java/src/test/java/ly/count/sdk/java/internal/MigrationHelperTests.java +++ b/sdk-java/src/test/java/ly/count/sdk/java/internal/MigrationHelperTests.java @@ -4,9 +4,9 @@ import java.io.File; import java.io.IOException; import java.nio.file.Files; -import java.util.HashMap; import java.util.Map; import java.util.Objects; +import java.util.concurrent.ConcurrentHashMap; import ly.count.sdk.java.Countly; import org.junit.After; import org.junit.Assert; @@ -156,7 +156,7 @@ public void applyMigrations_legacyToLatest() { MigrationHelper migrationHelper = new MigrationHelper(mock(Log.class)); migrationHelper.setupMigrations(storageProvider); Assert.assertEquals(0, migrationHelper.currentDataModelVersion); //legacy state - Map migrationParams = new HashMap<>(); + Map migrationParams = new ConcurrentHashMap<>(); migrationParams.put("sdk_path", TestUtils.getTestSDirectory()); //apply migrations migrationHelper.applyMigrations(migrationParams); @@ -179,7 +179,7 @@ public void applyMigrations_latestToLatest() throws IOException { migrationHelper.setupMigrations(storageProvider); Assert.assertEquals(expectedLatestSchemaVersion, migrationHelper.currentDataModelVersion); //latest state //run migration helper apply - migrationHelper.applyMigrations(new HashMap<>()); + migrationHelper.applyMigrations(new ConcurrentHashMap<>()); //check migration version is at the latest after apply both from class and file Assert.assertEquals(expectedLatestSchemaVersion, migrationHelper.currentDataModelVersion); Assert.assertEquals(expectedLatestSchemaVersion, TestUtils.getJsonStorageProperty(SDKStorage.key_migration_version)); @@ -203,7 +203,7 @@ public void applyMigrations_0to1() throws IOException { //run migration helper Assert.assertNull(storageProvider.getDeviceID()); Assert.assertNull(storageProvider.getDeviceIdType()); - Map migrationParams = new HashMap<>(); + Map migrationParams = new ConcurrentHashMap<>(); migrationParams.put("sdk_path", TestUtils.getTestSDirectory()); Assert.assertTrue(migrationHelper.migration_DeleteConfigFile_01(migrationParams)); @@ -291,7 +291,7 @@ public void applyMigrations_1to2_nothingToMigrate() throws IOException { setDataVersionInConfigFile(1); // set previous data version initStorage(); - Map migrationParams = new HashMap<>(); + Map migrationParams = new ConcurrentHashMap<>(); migrationParams.put("sdk_path", TestUtils.getTestSDirectory()); MigrationHelper migrationHelper = new MigrationHelper(mock(Log.class)); @@ -319,7 +319,7 @@ public void applyMigrations_1to2_nullMigrationParams() throws IOException { Assert.assertEquals(1, migrationHelper.currentDataModelVersion); migrationHelper.logger = Mockito.spy(migrationHelper.logger); - Assert.assertFalse(migrationHelper.migration_UserImplFile_02(new HashMap<>())); + Assert.assertFalse(migrationHelper.migration_UserImplFile_02(new ConcurrentHashMap<>())); Assert.assertEquals(2, migrationHelper.currentDataModelVersion); Mockito.verify(migrationHelper.logger, Mockito.times(1)).d("[MigrationHelper] migration_UserImplFile_02, No files to delete, returning"); } diff --git a/sdk-java/src/test/java/ly/count/sdk/java/internal/ModuleEventsTests.java b/sdk-java/src/test/java/ly/count/sdk/java/internal/ModuleEventsTests.java index f236e558f..688ee6c7a 100644 --- a/sdk-java/src/test/java/ly/count/sdk/java/internal/ModuleEventsTests.java +++ b/sdk-java/src/test/java/ly/count/sdk/java/internal/ModuleEventsTests.java @@ -1,9 +1,9 @@ package ly.count.sdk.java.internal; import java.io.IOException; -import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; import ly.count.sdk.java.Config; import ly.count.sdk.java.Countly; import org.junit.After; @@ -42,7 +42,7 @@ public void recordEvent() { TestUtils.validateEQSize(0, moduleEvents.eventQueue); //create segmentation - Map segmentation = new HashMap<>(); + Map segmentation = new ConcurrentHashMap<>(); segmentation.put("name", "Johny"); segmentation.put("weight", 67); segmentation.put("bald", true); @@ -154,13 +154,13 @@ public void recordEvent_invalidSegment() { TestUtils.validateEQSize(0, moduleEvents.eventQueue); //create segmentation - Map segmentation = new HashMap<>(); + Map segmentation = new ConcurrentHashMap<>(); segmentation.put("exam_name", "CENG 101"); segmentation.put("score", 67); segmentation.put("cheated", false); - segmentation.put("invalid", new HashMap<>()); + segmentation.put("invalid", new ConcurrentHashMap<>()); - Map expectedSegmentation = new HashMap<>(); + Map expectedSegmentation = new ConcurrentHashMap<>(); expectedSegmentation.put("exam_name", "CENG 101"); expectedSegmentation.put("score", 67); expectedSegmentation.put("cheated", false); @@ -310,7 +310,7 @@ public void endEvent_withSegmentation() { EventImpl timedEvent = moduleEvents.timedEvents.get(eKeys[0]); validateEvent(timedEvent, eKeys[0], null, 1, null, null); - Map segmentation = new HashMap<>(); + Map segmentation = new ConcurrentHashMap<>(); segmentation.put("hair_color", "red"); segmentation.put("hair_length", "short"); segmentation.put("chauffeur", "g3chauffeur"); // @@ -338,7 +338,7 @@ public void endEvent_withSegmentation_negativeCount() { EventImpl timedEvent = moduleEvents.timedEvents.get(eKeys[0]); validateEvent(timedEvent, eKeys[0], null, 1, null, null); - Map segmentation = new HashMap<>(); + Map segmentation = new ConcurrentHashMap<>(); segmentation.put("horse_name", "Alice"); segmentation.put("bet_amount", 300); segmentation.put("currency", "Dollar"); // diff --git a/sdk-java/src/test/java/ly/count/sdk/java/internal/ModuleFeedbackTests.java b/sdk-java/src/test/java/ly/count/sdk/java/internal/ModuleFeedbackTests.java index b64d50f8e..21110ac29 100644 --- a/sdk-java/src/test/java/ly/count/sdk/java/internal/ModuleFeedbackTests.java +++ b/sdk-java/src/test/java/ly/count/sdk/java/internal/ModuleFeedbackTests.java @@ -5,6 +5,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; import ly.count.sdk.java.Config; import ly.count.sdk.java.Countly; import org.json.JSONArray; @@ -411,7 +412,7 @@ public void reportFeedbackWidgetManually_nullWidgetResultValueKeys() { widgetResult.put("accepted", true); widgetResult.put("rating", 6); - Map expectedWidgetResult = new HashMap<>(); + Map expectedWidgetResult = new ConcurrentHashMap<>(); expectedWidgetResult.put("accepted", true); expectedWidgetResult.put("rating", 6); @@ -429,7 +430,7 @@ public void reportFeedbackWidgetManually_nullWidgetResultValueKeys() { public void reportFeedbackWidgetManually_nonExistingRatingField() { init(TestUtils.getConfigFeedback(Config.Feature.Events)); - Map widgetResult = new HashMap<>(); + Map widgetResult = new ConcurrentHashMap<>(); widgetResult.put("accepted", true); validateRecordingWidgetsManually(createFeedbackWidget(FeedbackWidgetType.nps, "nps1", "npsID1", new String[] { "sa" }), null, widgetResult, 0, false); @@ -445,7 +446,7 @@ public void reportFeedbackWidgetManually_nonExistingRatingField() { public void reportFeedbackWidgetManually_invalidRatingField() { init(TestUtils.getConfigFeedback(Config.Feature.Events)); - Map widgetResult = new HashMap<>(); + Map widgetResult = new ConcurrentHashMap<>(); widgetResult.put("rating", true); validateRecordingWidgetsManually(createFeedbackWidget(FeedbackWidgetType.nps, "nps1", "npsID1", new String[] { "sa" }), null, widgetResult, 0, false); @@ -461,7 +462,7 @@ public void reportFeedbackWidgetManually_invalidRatingField() { public void reportFeedbackWidgetManually_validRatingField() { init(TestUtils.getConfigFeedback(Config.Feature.Events)); - Map widgetResult = new HashMap<>(); + Map widgetResult = new ConcurrentHashMap<>(); widgetResult.put("rating", 11); validateRecordingWidgetsManually(createFeedbackWidget(FeedbackWidgetType.nps, "nps1", "npsID1", new String[] { "sa" }), null, widgetResult, 0, true); @@ -577,7 +578,7 @@ private ModuleEvents moduleEvents() { } private Map requiredWidgetSegmentation(String widgetId, Map widgetResult) { - Map segm = new HashMap<>(); + Map segm = new ConcurrentHashMap<>(); segm.put("platform", getOS()); segm.put("app_version", SDKCore.instance.config.getApplicationVersion()); segm.put("widget_id", widgetId); diff --git a/sdk-java/src/test/java/ly/count/sdk/java/internal/TestUtils.java b/sdk-java/src/test/java/ly/count/sdk/java/internal/TestUtils.java index fb37fbe80..8697a7c39 100644 --- a/sdk-java/src/test/java/ly/count/sdk/java/internal/TestUtils.java +++ b/sdk-java/src/test/java/ly/count/sdk/java/internal/TestUtils.java @@ -8,7 +8,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Comparator; -import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Scanner; @@ -155,14 +154,14 @@ protected static Map[] getCurrentRQ(File targetFolder, Log logge //check whether target folder is a directory or not if (!targetFolder.isDirectory()) { logger.e("[TestUtils] " + targetFolder.getAbsolutePath() + " is not a directory"); - return new HashMap[0]; + return new ConcurrentHashMap[0]; } //get all request files from target folder File[] requestFiles = getRequestFiles(targetFolder); //create array of request params - Map[] resultMapArray = new HashMap[requestFiles.length]; + Map[] resultMapArray = new ConcurrentHashMap[requestFiles.length]; for (int i = 0; i < requestFiles.length; i++) { File file = requestFiles[i]; @@ -274,12 +273,12 @@ private static Map parseRequestParams(File file) throws IOExcept try (Scanner scanner = new Scanner(file)) { String firstLine = scanner.nextLine(); if (Utils.isEmptyOrNull(firstLine)) { - return new HashMap<>(); + return new ConcurrentHashMap<>(); } String[] params = firstLine.split("&"); - Map paramMap = new HashMap<>(); + Map paramMap = new ConcurrentHashMap<>(); for (String param : params) { String[] pair = param.split("="); paramMap.put(Utils.urldecode(pair[0]), pair.length == 1 ? "" : Utils.urldecode(pair[1])); @@ -301,7 +300,7 @@ public static Map parseQueryParams(String data) { data = data.replace("?", ""); } String[] params = data.split("&"); - Map paramMap = new HashMap<>(); + Map paramMap = new ConcurrentHashMap<>(); for (String param : params) { String[] pair = param.split("="); paramMap.put(pair[0], pair[1]); diff --git a/sdk-java/src/test/java/ly/count/sdk/java/internal/TimedEventsTests.java b/sdk-java/src/test/java/ly/count/sdk/java/internal/TimedEventsTests.java index 795a0c73f..12df8e064 100644 --- a/sdk-java/src/test/java/ly/count/sdk/java/internal/TimedEventsTests.java +++ b/sdk-java/src/test/java/ly/count/sdk/java/internal/TimedEventsTests.java @@ -1,7 +1,7 @@ package ly.count.sdk.java.internal; -import java.util.HashMap; import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; import ly.count.sdk.java.Countly; import ly.count.sdk.java.Event; import org.junit.After; @@ -47,11 +47,11 @@ public void recordEventRegularFlow_base(boolean regularRecord) throws Interrupte Event tEvent = Countly.instance().timedEvent("key"); tEvent.setCount(5).setSum(133).setDuration(456); - Map segm = new HashMap<>(); + Map segm = new ConcurrentHashMap<>(); segm.put("1", "a"); segm.put("5", "b"); - Map targetSegm = new HashMap<>(); + Map targetSegm = new ConcurrentHashMap<>(); targetSegm.put("1", "a"); targetSegm.put("5", "b"); diff --git a/sdk-java/src/test/java/ly/count/sdk/java/internal/UtilsTests.java b/sdk-java/src/test/java/ly/count/sdk/java/internal/UtilsTests.java index a3c83858e..d6e2bf8aa 100644 --- a/sdk-java/src/test/java/ly/count/sdk/java/internal/UtilsTests.java +++ b/sdk-java/src/test/java/ly/count/sdk/java/internal/UtilsTests.java @@ -13,6 +13,7 @@ import java.util.EnumSet; import java.util.HashMap; import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; import ly.count.sdk.java.Config; import org.junit.Assert; import org.junit.Before; @@ -75,7 +76,7 @@ public void trimValues() { */ @Test public void fixSegmentKeysAndValues() { - Map segmentation = new HashMap<>(); + Map segmentation = new ConcurrentHashMap<>(); segmentation.put("key_10", "value1_"); segmentation.put("key_20", "value2_"); @@ -354,7 +355,7 @@ public void isValidDataType() { Assert.assertFalse(Utils.isValidDataType(null)); Assert.assertFalse(Utils.isValidDataType(new Object())); Assert.assertFalse(Utils.isValidDataType(new ArrayList<>())); - Assert.assertFalse(Utils.isValidDataType(new HashMap<>())); + Assert.assertFalse(Utils.isValidDataType(new ConcurrentHashMap<>())); } /**