Skip to content
This repository has been archived by the owner on Jan 14, 2018. It is now read-only.

spicemanager: always use isStarted() when checking if started. #214

Merged
merged 1 commit into from
Nov 12, 2013
Merged

spicemanager: always use isStarted() when checking if started. #214

merged 1 commit into from
Nov 12, 2013

Conversation

gkylafas
Copy link
Contributor

In my SpiceManager subclass, I override start(Context) and check if the manager is started to avoid receiving an IllegalStateException:

public class NetRequestManager extends SpiceManager {
@Override
    public synchronized void start(Context context) {
        if (!isStarted())
            super.start(context);
    }
}

However, there was a case where a user of my robospice 1.4.7-based application received exactly this:

java.lang.IllegalStateException: Already started.
        at com.octo.android.robospice.SpiceManager.start(SpiceManager.java:194)
        at gr.p.a.NetRequestManager.start(NetRequestManager.java:29)

Since SpiceManager.start() checks the value of runner instead of using isStarted(), it seems that in rare occasions the former may not be null while the latter is false. So, I changed the check to use isStarted().

I believe this is within the "spirit" of the library, since this is the only place where the value of runner is checked. Everywhere else the check is done using either isStopped or isStarted(). I have also run all the tests and none fails. However, I do not know why this occurs and what it means to create a new runner while the existing is not null.

There is a rare case where isStarted() == false but runner != null.

When this happens, even if a user of the library checks with
isStarted() before calling start(), he will not avoid the
IllegalStateException "Already started.".

So, always check if SpiceManager has started with isStarted().
@rciovati
Copy link
Contributor

Looks good to me. Thanks

rciovati added a commit that referenced this pull request Nov 12, 2013
spicemanager: always use isStarted() when checking if started.
@rciovati rciovati merged commit 643daf1 into stephanenicolas:master Nov 12, 2013
@gkylafas gkylafas deleted the spicemanager-always-use-isStarted branch November 12, 2013 17:27
@stephanenicolas
Copy link
Owner

Do you wanna release Riccardo ? Join me off record to get all keys...

S.
Le 12 nov. 2013 17:45, "Riccardo Ciovati" notifications@github.com a
écrit :

Merged #214 #214.


Reply to this email directly or view it on GitHubhttps://github.com//pull/214
.

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

Successfully merging this pull request may close these issues.

None yet

3 participants