Skip to content

1.x: distinctUntilChanged change erroneous behavior #4276

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public OperatorDistinctUntilChanged(Func2<? super U, ? super U, Boolean> compara

@Override
public Boolean call(U t1, U t2) {
return (t1 == t2 || (t1 != null && t1.equals(t2)));
return (t1 == t2 || (t2 != null && t2.equals(t1)));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a test case that fails without fix and passed with it

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An example:
Object t1 and t2 are of the same type and contains an object x1.
Object x1 is null in t1 and is not null in t2
Object t1 and t2 override equals which in turn calls the equals of x1.
A NullpointerException is thrown from t1 but not from t2.

This is a basic example but what I want to say is that applying equals on t1 does not means that it will result the same the other way around.
That's the type of behavior changes which should be fixed on the user side of the rxjava lib but which can create confusion and can be avoided.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current comparison is completely legal, same as Java 7's Objects.equals(). Why did you swap the variables? Implementation of equals should be symmetric: a.equals(b) == b.equals(a).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a broken equals implementation and not this library's problem.

}

@Override
Expand Down