Skip to content
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

QueryLoader closing previous result even if it's the same result #545

Closed
gregkorossy opened this issue May 1, 2017 · 1 comment
Closed
Labels

Comments

@gregkorossy
Copy link

Here are two methods of QueryLoader:

@Override
protected void onStartLoading() {
    if (result != null) {
        deliverResult(result);
    } else {
        forceLoad();
    }
}

@Override
public void deliverResult(Result<E> data) {
    if (isReset()) {
        if (result != null) {
            result.close();
        }
        return;
    }
    Result<E> previous = result;
    result = data;
    if (isStarted()) {
        super.deliverResult(result);
    }
    if (previous != null) {
        previous.close();
    }
}

As it is a Loader, it tries to use the previous results if available (onStartLoading()'s deliverResult(result);). This is cool, but the problem is that deliverResult(...) does not check whether the previous result is the same as the new one, and closes it anyway. This results in IllegalStateException when trying to use the same result again as it has been closed.

There's a quick fix for the problem in deliverResult(...), instead of

if (previous != null) {
    previous.close();
}

it should check whether the previous and current results are different objects:

if (previous != null && previous != data) {
    previous.close();
}
@npurushe npurushe added the bug label May 1, 2017
@npurushe
Copy link
Contributor

npurushe commented May 1, 2017

Thanks for the detailed bug report, yes that looks like the correct fix will update thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants