Giter Club home page Giter Club logo

Comments (3)

davidmoten avatar davidmoten commented on June 18, 2024 1

Fix deployed to Maven Central 0.1.30 (should be downloadable there in 10 minutes or so), thanks for the report and diagnosis!

from rxjava2-extras.

jhansche avatar jhansche commented on June 18, 2024

It seems that the logic of both retryWhenInstanceOf and failWhenInstanceOf are backwards:

// e = the actual error
// cls = the class passed into the retry or fail instance lists
if (e.throwable().getClass().isAssignableFrom(cls)) {

So if the thrown error is assignable from the retry/fail class, then it will work. Otherwise it won't. But you will virtually never actually want that. You should be able to pass a parent class to this list, and any subclass instance that is thrown will then match here.

"Assignable from" means you can assign the right side instance, to the left side class, without explicitly casting.

In other words:

 A.class.isAssignableFrom(B.class)
 // means this should work correctly:
 A a;  B b;  a = b;
 // and the opposite will require a cast:
 b = (B) a;

that's because if A is assignable from B, then an A variable can be assigned an instance of B. But if B is not assignable from A, then you can't simply assign it and instead you would have to cast it (which might fail with ClassCastException)

The correct fix is to flip the "isAssignableFrom" operands:

        @Override
        public Flowable<ErrorAndDuration> apply(ErrorAndDuration e) throws Exception {
            if (!exceptionPredicate.test(e.throwable())) {
                return Flowable.error(e.throwable());
            }
            for (Class<? extends Throwable> cls : failExceptions) {
                if (cls.isAssignableFrom(e.throwable().getClass())) {     // <--- this is flipped
                    return Flowable.error(e.throwable());
                }
            }
            if (retryExceptions.size() > 0) {
                for (Class<? extends Throwable> cls : retryExceptions) {
                    if (cls.isAssignableFrom(e.throwable().getClass())) {     // <--- this is flipped
                        return Flowable.just(e);
                    }
                }
                return Flowable.error(e.throwable());
            } else {
                return Flowable.just(e);
            }
        }

from rxjava2-extras.

davidmoten avatar davidmoten commented on June 18, 2024

Thanks for that! I'll knock up a failing unit test and apply your fix. You are very welcome to make a PR if you'd like otherwise I'll do the fix now.

from rxjava2-extras.

Related Issues (17)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.