LiveTex / sdk-android

Android SDK и демо-приложение для нового VisitorAPI
2 stars 4 forks source link

NPE при старте сессии #38

Open xBlackCat opened 4 months ago

xBlackCat commented 4 months ago

Версия SDK 1.3.1

Ошибка проявляется, т.к. в приходящем JSON нет поля employe

При старте сессии в логах NPE:

onMessage {"type":"state","status":"aiBot","showInput":false}
New connection state: CONNECTED
Error when parsing message
                 java.lang.NullPointerException: Attempt to invoke virtual method 'com.google.gson.JsonObject com.google.gson.JsonElement.getAsJsonObject()' on a null object reference
                    at ru.livetex.sdk.logic.EntityMapper$LivetexDialogStateDeserializer.deserialize(EntityMapper.java:163)
                    at ru.livetex.sdk.logic.EntityMapper$LivetexDialogStateDeserializer.deserialize(EntityMapper.java:155)
                    at com.google.gson.internal.bind.TreeTypeAdapter.read(TreeTypeAdapter.java:95)
                    at com.google.gson.Gson.fromJson(Gson.java:1361)
                    at com.google.gson.Gson.fromJson(Gson.java:1463)
                    at com.google.gson.Gson.fromJson(Gson.java:1406)
                    at ru.livetex.sdk.logic.EntityMapper$LivetexTypeModelDeserializer.deserialize(EntityMapper.java:61)
                    at ru.livetex.sdk.logic.EntityMapper$LivetexTypeModelDeserializer.deserialize(EntityMapper.java:49)
                    at com.google.gson.internal.bind.TreeTypeAdapter.read(TreeTypeAdapter.java:95)
                    at com.google.gson.Gson.fromJson(Gson.java:1361)
                    at com.google.gson.Gson.fromJson(Gson.java:1262)
                    at com.google.gson.Gson.fromJson(Gson.java:1171)
                    at com.google.gson.Gson.fromJson(Gson.java:1107)
                    at ru.livetex.sdk.logic.EntityMapper.toEntity(EntityMapper.java:46)
                    at ru.livetex.sdk.logic.LiveTexMessagesHandler.onMessage(LiveTexMessagesHandler.java:83)
                    at ru.livetex.sdk.network.websocket.LiveTexWebsocketListener.onMessage(LiveTexWebsocketListener.java:39)
                    at okhttp3.internal.ws.RealWebSocket.onReadMessage(RealWebSocket.kt:392)
                    at okhttp3.internal.ws.WebSocketReader.readMessageFrame(WebSocketReader.kt:255)
                    at okhttp3.internal.ws.WebSocketReader.processNextFrame(WebSocketReader.kt:111)
                    at okhttp3.internal.ws.RealWebSocket.loopReader(RealWebSocket.kt:307)
                    at okhttp3.internal.ws.RealWebSocket$connect$1.onResponse(RealWebSocket.kt:195)
                    at okhttp3.internal.connection.RealCall$AsyncCall.run(RealCall.kt:529)
                    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
                    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644)
                    at java.lang.Thread.run(Thread.java:1012)
maxxx commented 3 months ago

исправил в 1.3.2

xBlackCat commented 2 months ago

Всё ещё есть ошибка при старте сессии, если приходит такое сообщение:

onMessage {
  "type" : "state",
  "status" : "aiBot",
  "employeeStatus" : null,
  "employee" : null,
  "showInput" : false
}

здесь поле employee есть, но содержит null. В результате аналогичный эксепшн:


Error when parsing message
com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Not a JSON Object: null
    at com.google.gson.Gson.fromJson(Gson.java:1372)
    at com.google.gson.Gson.fromJson(Gson.java:1463)
    at com.google.gson.Gson.fromJson(Gson.java:1406)
    at ru.livetex.sdk.logic.EntityMapper$LivetexTypeModelDeserializer.deserialize(EntityMapper.java:61)
    at ru.livetex.sdk.logic.EntityMapper$LivetexTypeModelDeserializer.deserialize(EntityMapper.java:49)
    at com.google.gson.internal.bind.TreeTypeAdapter.read(TreeTypeAdapter.java:95)
    at com.google.gson.Gson.fromJson(Gson.java:1361)
    at com.google.gson.Gson.fromJson(Gson.java:1262)
    at com.google.gson.Gson.fromJson(Gson.java:1171)
    at com.google.gson.Gson.fromJson(Gson.java:1107)
    at ru.livetex.sdk.logic.EntityMapper.toEntity(EntityMapper.java:46)
    at ru.livetex.sdk.logic.LiveTexMessagesHandler.onMessage(LiveTexMessagesHandler.java:83)
    at ru.livetex.sdk.network.websocket.LiveTexWebsocketListener.onMessage(LiveTexWebsocketListener.java:39)
    at okhttp3.internal.ws.RealWebSocket.onReadMessage(RealWebSocket.kt:392)
    at okhttp3.internal.ws.WebSocketReader.readMessageFrame(WebSocketReader.kt:255)
    at okhttp3.internal.ws.WebSocketReader.processNextFrame(WebSocketReader.kt:111)
    at okhttp3.internal.ws.RealWebSocket.loopReader(RealWebSocket.kt:307)
    at okhttp3.internal.ws.RealWebSocket$connect$1.onResponse(RealWebSocket.kt:195)
    at okhttp3.internal.connection.RealCall$AsyncCall.run(RealCall.kt:529)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644)
    at java.lang.Thread.run(Thread.java:1012)
Caused by: java.lang.IllegalStateException: Not a JSON Object: null
    at com.google.gson.JsonElement.getAsJsonObject(JsonElement.java:165)
    at ru.livetex.sdk.logic.EntityMapper$LivetexDialogStateDeserializer.deserialize(EntityMapper.java:164)
    at ru.livetex.sdk.logic.EntityMapper$LivetexDialogStateDeserializer.deserialize(EntityMapper.java:155)
    at com.google.gson.internal.bind.TreeTypeAdapter.read(TreeTypeAdapter.java:95)
    at com.google.gson.Gson.fromJson(Gson.java:1361)
    at com.google.gson.Gson.fromJson(Gson.java:1463) 
    at com.google.gson.Gson.fromJson(Gson.java:1406) 
    at ru.livetex.sdk.logic.EntityMapper$LivetexTypeModelDeserializer.deserialize(EntityMapper.java:61) 
    at ru.livetex.sdk.logic.EntityMapper$LivetexTypeModelDeserializer.deserialize(EntityMapper.java:49) 
    at com.google.gson.internal.bind.TreeTypeAdapter.read(TreeTypeAdapter.java:95) 
    at com.google.gson.Gson.fromJson(Gson.java:1361) 
    at com.google.gson.Gson.fromJson(Gson.java:1262) 
    at com.google.gson.Gson.fromJson(Gson.java:1171) 
    at com.google.gson.Gson.fromJson(Gson.java:1107) 
    at ru.livetex.sdk.logic.EntityMapper.toEntity(EntityMapper.java:46) 
    at ru.livetex.sdk.logic.LiveTexMessagesHandler.onMessage(LiveTexMessagesHandler.java:83) 
    at ru.livetex.sdk.network.websocket.LiveTexWebsocketListener.onMessage(LiveTexWebsocketListener.java:39) 
    at okhttp3.internal.ws.RealWebSocket.onReadMessage(RealWebSocket.kt:392) 
    at okhttp3.internal.ws.WebSocketReader.readMessageFrame(WebSocketReader.kt:255) 
    at okhttp3.internal.ws.WebSocketReader.processNextFrame(WebSocketReader.kt:111) 
    at okhttp3.internal.ws.RealWebSocket.loopReader(RealWebSocket.kt:307) 
    at okhttp3.internal.ws.RealWebSocket$connect$1.onResponse(RealWebSocket.kt:195) 
    at okhttp3.internal.connection.RealCall$AsyncCall.run(RealCall.kt:529) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644) 
    at java.lang.Thread.run(Thread.java:1012) ```
maxxx commented 2 months ago

в 1.3.3 должно исправиться