Skip to content

Commit

Permalink
fix: catch and prevent index out bound exception (#108)
Browse files Browse the repository at this point in the history
  • Loading branch information
qingzhuozhen authored Mar 6, 2023
1 parent 8b03d60 commit 7a4eb11
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import com.amplitude.core.utilities.EventsFileStorage
import com.amplitude.core.utilities.toEvents
import kotlinx.coroutines.launch
import org.json.JSONArray
import org.json.JSONException
import java.io.FileNotFoundException

class IdentifyInterceptFileStorageHandler(
Expand Down Expand Up @@ -39,6 +38,10 @@ class IdentifyInterceptFileStorageHandler(
continue
}
val eventsList = JSONArray(eventsString).toEvents()
if (eventsList.isEmpty()) {
removeFile(eventPath as String)
continue
}
var events = eventsList
if (event == null) {
event = eventsList[0]
Expand All @@ -48,7 +51,7 @@ class IdentifyInterceptFileStorageHandler(
val userProperties = IdentifyInterceptorUtil.mergeIdentifyList(events)
identifyEventUserProperties?.putAll(userProperties)
removeFile(eventPath as String)
} catch (e: JSONException) {
} catch (e: Exception) {
logger.warn("Identify Merge error: " + e.message)
removeFile(eventPath as String)
}
Expand Down Expand Up @@ -122,7 +125,7 @@ class IdentifyInterceptFileStorageHandler(
val listUserProperties = IdentifyInterceptorUtil.mergeIdentifyList(events)
userProperties.putAll(listUserProperties)
removeFile(eventPath as String)
} catch (e: JSONException) {
} catch (e: Exception) {
logger.warn("Identify Merge error: " + e.message)
removeFile(eventPath as String)
}
Expand Down

0 comments on commit 7a4eb11

Please sign in to comment.