Skip to content

Commit

Permalink
Fix AssertionError while loading enum from String
Browse files Browse the repository at this point in the history
  • Loading branch information
vRallev committed Nov 13, 2015
1 parent e5c76a3 commit d81de8c
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions library/src/main/java/com/evernote/android/job/JobRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,13 @@
import android.text.TextUtils;

import com.evernote.android.job.util.JobApi;
import com.evernote.android.job.util.JobCat;
import com.evernote.android.job.util.JobPreconditions;
import com.evernote.android.job.util.JobUtil;
import com.evernote.android.job.util.support.PersistableBundleCompat;

import net.vrallev.android.cat.CatLog;

import java.util.concurrent.TimeUnit;

/**
Expand Down Expand Up @@ -67,6 +70,8 @@ public final class JobRequest {
*/
public static final NetworkType DEFAULT_NETWORK_TYPE = NetworkType.ANY;

private static final CatLog CAT = new JobCat("JobRequest");

private final Builder mBuilder;
private final JobApi mJobApi;

Expand Down Expand Up @@ -412,15 +417,25 @@ private Builder(Cursor cursor) throws Exception {
mEndMs = cursor.getLong(cursor.getColumnIndex(JobStorage.COLUMN_END_MS));

mBackoffMs = cursor.getLong(cursor.getColumnIndex(JobStorage.COLUMN_BACKOFF_MS));
mBackoffPolicy = BackoffPolicy.valueOf(cursor.getString(cursor.getColumnIndex(JobStorage.COLUMN_BACKOFF_POLICY)));
try {
mBackoffPolicy = BackoffPolicy.valueOf(cursor.getString(cursor.getColumnIndex(JobStorage.COLUMN_BACKOFF_POLICY)));
} catch (Throwable t) {
CAT.e(t); // https://gist.github.com/vRallev/574563f0e3fe636b19a7
mBackoffPolicy = DEFAULT_BACKOFF_POLICY;
}

mIntervalMs = cursor.getLong(cursor.getColumnIndex(JobStorage.COLUMN_INTERVAL_MS));

mRequirementsEnforced = cursor.getInt(cursor.getColumnIndex(JobStorage.COLUMN_REQUIREMENTS_ENFORCED)) > 0;
mRequiresCharging = cursor.getInt(cursor.getColumnIndex(JobStorage.COLUMN_REQUIRES_CHARGING)) > 0;
mRequiresDeviceIdle = cursor.getInt(cursor.getColumnIndex(JobStorage.COLUMN_REQUIRES_DEVICE_IDLE)) > 0;
mExact = cursor.getInt(cursor.getColumnIndex(JobStorage.COLUMN_EXACT)) > 0;
mNetworkType = NetworkType.valueOf(cursor.getString(cursor.getColumnIndex(JobStorage.COLUMN_NETWORK_TYPE)));
try {
mNetworkType = NetworkType.valueOf(cursor.getString(cursor.getColumnIndex(JobStorage.COLUMN_NETWORK_TYPE)));
} catch (Throwable t) {
CAT.e(t); // https://gist.github.com/vRallev/574563f0e3fe636b19a7
mNetworkType = DEFAULT_NETWORK_TYPE;
}

mExtrasXml = cursor.getString(cursor.getColumnIndex(JobStorage.COLUMN_EXTRAS));

Expand Down

0 comments on commit d81de8c

Please sign in to comment.