У некоторых пользователей в моем приложении выдается Fatal Exception: com.google.gson.JsonSyntaxException. Я использую gson для записи и чтения данных в кэш LRU диска. Как я понимаю, это исключение происходит, когда я читаю данные из кэша.
Так я создал json экземпляр:
Gson gson = new Gson();
Это исключение происходит в Android 5,6,7 , 8. Это статистика Crashlytics.
Это трассировка стека исключений из Crashlytics:
Fatal Exception: com.google.gson.JsonSyntaxException: Nov 5, 2019 20:18:24
at com.google.gson.internal.bind.DateTypeAdapter.deserializeToDate(DateTypeAdapter.java:87)
at com.google.gson.internal.bind.DateTypeAdapter.read(DateTypeAdapter.java:75)
at com.google.gson.internal.bind.DateTypeAdapter.read(DateTypeAdapter.java:46)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:131)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:222)
at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.read(TypeAdapterRuntimeTypeWrapper.java:41)
at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:82)
at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:61)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:131)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:222)
at com.google.gson.Gson.fromJson(Gson.java:927)
at com.google.gson.Gson.fromJson(Gson.java:892)
at com.google.gson.Gson.fromJson(Gson.java:841)
at com.google.gson.Gson.fromJson(Gson.java:813)
at com.example.data.repository.MbCacheImpl.getDashboard(MbCacheImpl.java:44)
at com.example.data.repository.DataRepository.getDashboard(DataRepository.java:64)
at com.example.ui.main.main.TabMainViewModel.loadDashboard(TabMainViewModel.java:289)
at com.example.ui.main.main.TabMainViewModel.loadData(TabMainViewModel.java:260)
at com.example.ui.base.BaseDataViewModel$onAttach$1.onAvailable(BaseDataViewModel.java:124)
at android.net.ConnectivityManager$CallbackHandler.handleMessage(ConnectivityManager.java:3108)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.os.HandlerThread.run(HandlerThread.java:61)
Caused by java.text.ParseException: Failed to parse date ["Nov 5, 2019
20:18:24"]: Invalid number: Nov
at com.google.gson.internal.bind.util.ISO8601Utils.parse(ISO8601Utils.java:274)
at com.google.gson.internal.bind.DateTypeAdapter.deserializeToDate(DateTypeAdapter.java:85)
at com.google.gson.internal.bind.DateTypeAdapter.read(DateTypeAdapter.java:75)
at com.google.gson.internal.bind.DateTypeAdapter.read(DateTypeAdapter.java:46)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:131)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:222)
at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.read(TypeAdapterRuntimeTypeWrapper.java:41)
at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:82)
at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:61)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:131)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:222)
at com.google.gson.Gson.fromJson(Gson.java:927)
at com.google.gson.Gson.fromJson(Gson.java:892)
at com.google.gson.Gson.fromJson(Gson.java:841)
at com.google.gson.Gson.fromJson(Gson.java:813)
at com.example.data.repository.MbCacheImpl.getDashboard(MbCacheImpl.java:44)
at com.example.data.repository.DataRepository.getDashboard(DataRepository.java:64)
at com.example.ui.main.main.TabMainViewModel.loadDashboard(TabMainViewModel.java:289)
at com.example.ui.main.main.TabMainViewModel.loadData(TabMainViewModel.java:260)
at com.example.ui.base.BaseDataViewModel$onAttach$1.onAvailable(BaseDataViewModel.java:124)
at android.net.ConnectivityManager$CallbackHandler.handleMessage(ConnectivityManager.java:3108)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.os.HandlerThread.run(HandlerThread.java:61)
Caused by java.lang.NumberFormatException: Invalid number: Nov
at com.google.gson.internal.bind.util.ISO8601Utils.parseInt(ISO8601Utils.java:311)
at com.google.gson.internal.bind.util.ISO8601Utils.parse(ISO8601Utils.java:129)
at com.google.gson.internal.bind.DateTypeAdapter.deserializeToDate(DateTypeAdapter.java:85)
at com.google.gson.internal.bind.DateTypeAdapter.read(DateTypeAdapter.java:75)
at com.google.gson.internal.bind.DateTypeAdapter.read(DateTypeAdapter.java:46)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:131)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:222)
at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.read(TypeAdapterRuntimeTypeWrapper.java:41)
at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:82)
at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:61)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:131)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:222)
at com.google.gson.Gson.fromJson(Gson.java:927)
at com.google.gson.Gson.fromJson(Gson.java:892)
at com.google.gson.Gson.fromJson(Gson.java:841)
at com.google.gson.Gson.fromJson(Gson.java:813)
at com.example.data.repository.MbCacheImpl.getDashboard(MbCacheImpl.java:44)
at com.example.data.repository.DataRepository.getDashboard(DataRepository.java:64)
at com.example.ui.main.main.TabMainViewModel.loadDashboard(TabMainViewModel.java:289)
at com.example.ui.main.main.TabMainViewModel.loadData(TabMainViewModel.java:260)
at com.example.ui.base.BaseDataViewModel$onAttach$1.onAvailable(BaseDataViewModel.java:124)
at android.net.ConnectivityManager$CallbackHandler.handleMessage(ConnectivityManager.java:3108)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.os.HandlerThread.run(HandlerThread.java:61)