Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ss_inapps) - fix in-app id data type conversion from Int to Long fo SS in-apps SDK-4246 #731

Merged
merged 1 commit into from
Jan 16, 2025

Conversation

piyush-kukadiya
Copy link
Contributor

Issue happened in below code

fun loadSuppressedCSAndEvaluatedSSInAppsIds() {
    storeRegistry.inAppStore?.let { store ->
        evaluatedServerSideCampaignIds.putAll(JsonUtil.mapFromJson(store.readEvaluatedServerSideInAppIds()))
        suppressedClientSideInApps.putAll(JsonUtil.mapFromJson(store.readSuppressedClientSideInAppIds()))
    }
}
  1. store.readEvaluatedServerSideInAppIds() returns in-app Ids as Int instead of Long and evaluatedServerSideCampaignIds expects in-app Ids as Long
  2. Below 7.2.0 it was working as expected but in 7.2.0 we bumped kotlin version to 2.0.10 which caused an issue.
  3. Kotlin created strict rule regarding Int and Long comparison inside lambda. Basically it’s not allowed to compare Int with Long in lambda from 1.8.0 onwards.

store.readEvaluatedServerSideInAppIds() reads in-app Ids from shared preference as a String and converts it to JSONObject using new JSONObject(string from SP) . JSONObject internally converts in-app id to Int instead of Long which is the root cause. However nothing can be done here as thats how JSONObject works.

Solution implemented as below:

  1. in-app ids will always be a number in JSONObject, so consider it as a Number
  2. Convert JSONObject to a Map. evaluatedServerSideCampaignIds has generic type declared as <String,MutableList<Long>> but at runtime type is erased and hence during conversion MutableList contains an Int
  3. Now covert all Ints in MutableList to Longs and proceed as before.

Note
As per BE contract in-app ids must be passed as numeric and not text hence we are not making any changes to MutableList type here. Also loadSuppressedCSAndEvaluatedSSInAppsIds() method called only once in a session, during CT instance creation, hence there won't be much performance impact of Int to Long conversion.

@CTLalit CTLalit merged commit d05ace8 into develop Jan 16, 2025
4 checks passed
@CTLalit CTLalit deleted the bug/ss_inapps/SDK-4246 branch January 16, 2025 11:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants