0

I've been reading to the article https://github.com/ReactiveX/RxJava/wiki/What's-different-in-2.0#error-handling to solve my problem which is :

io.reactivex.exceptions.UndeliverableException: The exception could not be delivered to the consumer because it has already canceled/disposed the flow or the exception has nowhere to go to begin with. Further reading: https://github.com/ReactiveX/RxJava/wiki/What's-different-in-2.0#error-handling | java.lang.StackOverflowError: stack size 1037KB
        at io.reactivex.plugins.RxJavaPlugins.onError(RxJavaPlugins.java:367)
        at io.reactivex.internal.schedulers.ScheduledRunnable.run(ScheduledRunnable.java:69)
        at io.reactivex.internal.schedulers.ScheduledRunnable.call(ScheduledRunnable.java:57)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:301)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
        at java.lang.Thread.run(Thread.java:764)
     Caused by: java.lang.StackOverflowError: stack size 1037KB

I know that this StackOverflow is caused by recursive method or function call, been trying to check which method that call itself over and over. Finally, I came up with this solution :

private class CastingDeserializer : StdDeserializer<Casting>(Casting::class.java) {
 override fun deserialize(jp: JsonParser, ctxt: DeserializationContext?): Casting{
            val mappers = jp.codec
            val root = mappers.readTree<JsonNode>(jp)

            val type = root.get("type").asText()

            return if (!type.isNullOrEmpty()){
                mappers.treeToValue(root, getCastingClass(type))
            } else {
                try {
                    Thread.sleep(2000)
                } catch (e: InterruptedException){
                    e.printStackTrace()
                }
                mappers.treeToValue(root, getCastingClass(type))
            }

.....
}

and before I only make the return like this:

return mappers.treeToValue(root, getTransactionClass(type))

This method will be called by :

private val jacksonConverterFactory by lazy {
        val objMapper = ObjectMapper()
                .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)

        ..................
        objMapper.registerModule(someModule)

        val castingModule= SimpleModule()
        castingModule.addDeserializer(Casting::class.java, CastingDeserializer())
        objMapper .registerModule(castingModule)

        objMapper .setAnnotationIntrospector(CustomAnnotationInspector())
        objMapper .registerKotlinModule()

        return@lazy JacksonConverterFactory.create(objMapper)
    }

I make a thread for the function to give some delay before calling it again. But I still face the same issue, does anyone know how to implement the proper handling here?, please kindly help me, Thank you

Anne
  • 31
  • 1
  • 6
  • https://stackoverflow.com/questions/43525052/rxjava2-observable-take-throws-undeliverableexception does you trying this solution? – rost Dec 10 '21 at 06:13
  • @rost I did try that, but didn't work out. – Anne Dec 10 '21 at 06:31
  • @rost this crash happens when there is data change manually from the server, before any changes, it looks fine – Anne Dec 10 '21 at 06:33
  • Can you show a class, where you using result of this call? I interested your disposable and work with it. – rost Dec 10 '21 at 06:37
  • I'm afraid I can't. It's too complex and pretty classified, but this class that I'm using is for the endpoint generator that will be called by every single activity class that needs to request data from the server and the method will be called by Jackson converter factory variable @rost – Anne Dec 10 '21 at 06:53
  • The thing is that this code works fine with other requests but only for showing a specific list of data, it throws an exception like above @rost – Anne Dec 10 '21 at 06:54
  • as you can take a look to my updated code above @rost – Anne Dec 10 '21 at 06:57
  • I assume that you are using your disposable incorrectly when calling request, but cannot help without additional information – rost Dec 10 '21 at 08:23

0 Answers0