From: Damyan Ivanov Date: Sun, 5 May 2019 15:17:05 +0000 (+0300) Subject: replace assertions with good old if() X-Git-Tag: v0.10.0~12 X-Git-Url: https://git.ktnx.net/?a=commitdiff_plain;h=112fd782066d4eb759a104eaf7116b310e0d47d5;p=mobile-ledger.git replace assertions with good old if() assertions aren't implemented in Android's Java? --- diff --git a/app/src/main/java/net/ktnx/mobileledger/async/UpdateAccountsTask.java b/app/src/main/java/net/ktnx/mobileledger/async/UpdateAccountsTask.java index 328eff45..667bf998 100644 --- a/app/src/main/java/net/ktnx/mobileledger/async/UpdateAccountsTask.java +++ b/app/src/main/java/net/ktnx/mobileledger/async/UpdateAccountsTask.java @@ -35,7 +35,7 @@ public class UpdateAccountsTask extends AsyncTask newList = new ArrayList<>(); diff --git a/app/src/main/java/net/ktnx/mobileledger/model/Data.java b/app/src/main/java/net/ktnx/mobileledger/model/Data.java index 243cb361..223a61e8 100644 --- a/app/src/main/java/net/ktnx/mobileledger/model/Data.java +++ b/app/src/main/java/net/ktnx/mobileledger/model/Data.java @@ -78,7 +78,7 @@ public final class Data { public static int getProfileIndex(MobileLedgerProfile profile) { try (LockHolder ignored = profilesLocker.lockForReading()) { List prList = profiles.getValue(); - assert prList != null; + if (prList == null) throw new AssertionError(); for (int i = 0; i < prList.size(); i++) { MobileLedgerProfile p = prList.get(i); if (p.equals(profile)) return i; @@ -91,7 +91,7 @@ public final class Data { public static int getProfileIndex(String profileUUID) { try (LockHolder ignored = profilesLocker.lockForReading()) { List prList = profiles.getValue(); - assert prList != null; + if (prList == null) throw new AssertionError(); for (int i = 0; i < prList.size(); i++) { MobileLedgerProfile p = prList.get(i); if (p.getUuid().equals(profileUUID)) return i; diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfileDetailFragment.java b/app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfileDetailFragment.java index 470a3eae..c0944f9a 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfileDetailFragment.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfileDetailFragment.java @@ -108,7 +108,7 @@ public class ProfileDetailFragment extends Fragment implements HueRingDialog.Hue String.format("[fragment] removing profile %s", mProfile.getUuid())); mProfile.removeFromDB(); ArrayList oldList = Data.profiles.getValue(); - assert oldList != null; + if (oldList == null) throw new AssertionError(); ArrayList newList = (ArrayList) oldList.clone(); newList.remove(mProfile); @@ -144,7 +144,7 @@ public class ProfileDetailFragment extends Fragment implements HueRingDialog.Hue int index = Data.getProfileIndex(mProfile); MobileLedgerProfile newProfile = new MobileLedgerProfile(mProfile); final ArrayList profiles = Data.profiles.getValue(); - assert profiles != null; + if (profiles == null) throw new AssertionError(); profiles.set(index, newProfile); if (mProfile.equals(Data.profile.getValue())) Data.profile.setValue(newProfile); } @@ -193,7 +193,7 @@ public class ProfileDetailFragment extends Fragment implements HueRingDialog.Hue updateProfileFromUI(); mProfile.storeInDB(); final ArrayList profiles = Data.profiles.getValue(); - assert profiles != null; + if (profiles == null) throw new AssertionError(); ArrayList newList = (ArrayList) profiles.clone(); newList.add(mProfile); diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfilesRecyclerViewAdapter.java b/app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfilesRecyclerViewAdapter.java index 4ad4fdbe..eb3d0a0d 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfilesRecyclerViewAdapter.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfilesRecyclerViewAdapter.java @@ -71,7 +71,7 @@ public class ProfilesRecyclerViewAdapter @NonNull RecyclerView.ViewHolder viewHolder, @NonNull RecyclerView.ViewHolder target) { final ArrayList profiles = Data.profiles.getValue(); - assert profiles != null; + if (profiles == null) throw new AssertionError(); Collections.swap(profiles, viewHolder.getAdapterPosition(), target.getAdapterPosition()); MobileLedgerProfile.storeProfilesOrder(); @@ -165,7 +165,7 @@ public class ProfilesRecyclerViewAdapter @Override public void onBindViewHolder(@NonNull final ProfileListViewHolder holder, int position) { final ArrayList profiles = Data.profiles.getValue(); - assert profiles != null; + if (profiles == null) throw new AssertionError(); final MobileLedgerProfile profile = profiles.get(position); final MobileLedgerProfile currentProfile = Data.profile.getValue(); debug("profiles", String.format(Locale.ENGLISH, "pos %d: %s, current: %s", position,