Bug 1240579 - Remove org.mozilla.gecko.Assert from Fennec. f=margaret r=me

Having org.mozilla.gecko.Assert in both the main APK and the
androidTest APK is not well supported by the Android toolchain.  It's
much simpler to remove the one in the main APK, which has never
provided much value.

--HG--
extra : commitid : HMk3SKKEP8A
extra : rebase_source : f23e08aeb614d7d4d7eedc7fd74f1f8435c1d476
extra : amend_source : 0a9493bf6303b22e9385dc496e7fcc693660a8b8
This commit is contained in:
Nick Alexander 2016-01-18 11:29:26 -08:00
Родитель 650004648d
Коммит 35bfd7d7fc
8 изменённых файлов: 17 добавлений и 103 удалений

Просмотреть файл

@ -1,84 +0,0 @@
package org.mozilla.gecko;
/**
* Static helper class to provide debug assertions for Java.
*
* Used in preference to JSR 41 assertions due to their difficulty of use on Android and their
* poor behaviour w.r.t bytecode bloat (and to a lesser extent, runtime performance when disabled)
*
* Calls to methods in this class will be stripped by Proguard for release builds, so may be used
* arbitrarily liberally at zero cost.
* Under no circumstances should the argument expressions to methods in this class have side effects
* relevant to the correctness of execution of the program. Such side effects shall not be checked
* for when stripping assertions.
*/
public class Assert {
// Static helper class.
private Assert() {}
/**
* Verify that two objects are equal according to their equals method.
*/
public static void equal(Object a, Object b) {
equal(a, b, "Assertion failure: !" + a + ".equals(" + b + ')');
}
public static void equal(Object a, Object b, String message) {
isTrue(a.equals(b), message);
}
/**
* Verify that an arbitrary boolean expression is true.
*/
public static void isTrue(boolean a) {
isTrue(a, null);
}
public static void isTrue(boolean a, String message) {
if (!a) {
throw new AssertionError(message);
}
}
/**
* Verify that an arbitrary boolean expression is false.
*/
public static void isFalse(boolean a) {
isTrue(a, null);
}
public static void isFalse(boolean a, String message) {
if (a) {
throw new AssertionError(message);
}
}
/**
* Verify that a given object is null.
*/
public static void isNull(Object o) {
isNull(o, "Assertion failure: " + o + " must be null!");
}
public static void isNull(Object o, String message) {
isTrue(o == null, message);
}
/**
* Verify that a given object is non-null.
*/
public static void isNotNull(Object o) {
isNotNull(o, "Assertion failure: " + o + " cannot be null!");
}
public static void isNotNull(Object o, String message) {
isTrue(o != null, message);
}
/**
* Fail. Should be used whenever an impossible state is encountered (such as the default branch
* of a switch over all possible values of an enum: such an assertion may save future developers
* time when they try to add new states)
*/
public static void fail() {
isTrue(false);
}
public static void fail(String message) {
isTrue(false, message);
}
}

Просмотреть файл

@ -16,7 +16,6 @@ import java.util.Set;
import org.json.JSONException;
import org.json.JSONObject;
import org.mozilla.gecko.Assert;
import org.mozilla.gecko.GeckoAppShell;
import org.mozilla.gecko.Telemetry;
import org.mozilla.gecko.util.ThreadUtils;
@ -109,7 +108,6 @@ public class LocalURLMetadata implements URLMetadata {
}
} catch (JSONException e) {
Log.w(LOGTAG, "Exception processing touchIconList for LocalURLMetadata; ignoring.", e);
Assert.isTrue(false);
}
return Collections.unmodifiableMap(data);

Просмотреть файл

@ -11,7 +11,6 @@ import android.content.Intent;
import android.os.IBinder;
import android.util.Log;
import org.mozilla.gecko.Assert;
import org.mozilla.gecko.overlays.service.sharemethods.AddBookmark;
import org.mozilla.gecko.overlays.service.sharemethods.AddToReadingList;
import org.mozilla.gecko.overlays.service.sharemethods.SendTab;
@ -122,8 +121,7 @@ public class OverlayActionService extends Service {
Log.e(LOGTAG, "Share failed: " + result);
break;
default:
Assert.fail("Unknown share method result code: " + result);
break;
throw new IllegalStateException("Unknown share method result code: " + result);
}
}
});

Просмотреть файл

@ -7,7 +7,6 @@ package org.mozilla.gecko.overlays.ui;
import java.util.Collection;
import org.mozilla.gecko.AppConstants;
import org.mozilla.gecko.Assert;
import org.mozilla.gecko.R;
import org.mozilla.gecko.db.RemoteClient;
import org.mozilla.gecko.overlays.ui.SendTabList.State;
@ -19,8 +18,6 @@ import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
public class SendTabDeviceListArrayAdapter extends ArrayAdapter<RemoteClient> {
@SuppressWarnings("unused")
@ -174,7 +171,7 @@ public class SendTabDeviceListArrayAdapter extends ArrayAdapter<RemoteClient> {
showDummyRecord(getContext().getResources().getString(R.string.overlay_share_send_other));
break;
default:
Assert.fail("Unexpected state transition: " + newState);
throw new IllegalStateException("Unexpected state transition: " + newState);
}
}

Просмотреть файл

@ -9,8 +9,6 @@ import static org.mozilla.gecko.overlays.ui.SendTabList.State.SHOW_DEVICES;
import java.util.Arrays;
import org.mozilla.gecko.AppConstants.Versions;
import org.mozilla.gecko.Assert;
import org.mozilla.gecko.R;
import org.mozilla.gecko.Telemetry;
import org.mozilla.gecko.TelemetryContract;
@ -87,7 +85,9 @@ public class SendTabList extends ListView {
@Override
public void setAdapter(ListAdapter adapter) {
Assert.isTrue(adapter instanceof SendTabDeviceListArrayAdapter);
if (!(adapter instanceof SendTabDeviceListArrayAdapter)) {
throw new IllegalArgumentException("adapter must be a SendTabDeviceListArrayAdapter instance");
}
clientListAdapter = (SendTabDeviceListArrayAdapter) adapter;
super.setAdapter(adapter);

Просмотреть файл

@ -8,7 +8,6 @@ package org.mozilla.gecko.overlays.ui;
import java.net.URISyntaxException;
import org.mozilla.gecko.AppConstants;
import org.mozilla.gecko.Assert;
import org.mozilla.gecko.GeckoProfile;
import org.mozilla.gecko.Locales;
import org.mozilla.gecko.R;
@ -369,7 +368,9 @@ public class ShareDialog extends Locales.LocaleAwareActivity implements SendTabT
@Override
public void onSendTabActionSelected() {
// This requires an override intent.
Assert.isTrue(sendTabOverrideIntent != null);
if (sendTabOverrideIntent == null) {
throw new IllegalStateException("sendTabOverrideIntent must not be null");
}
startActivity(sendTabOverrideIntent);
finish();
@ -378,7 +379,9 @@ public class ShareDialog extends Locales.LocaleAwareActivity implements SendTabT
@Override
public void onSendTabTargetSelected(String targetGUID) {
// targetGUID being null with no override intent should be an impossible state.
Assert.isTrue(targetGUID != null);
if (targetGUID == null) {
throw new IllegalStateException("targetGUID must not be null");
}
Intent serviceIntent = getServiceIntent(ShareMethod.Type.SEND_TAB);

Просмотреть файл

@ -10,7 +10,6 @@ import java.io.IOException;
import org.json.JSONException;
import org.json.JSONObject;
import org.mozilla.gecko.Assert;
import org.mozilla.gecko.GeckoThread;
import android.content.BroadcastReceiver;
@ -32,8 +31,12 @@ public class InstallListener extends BroadcastReceiver {
mData = data;
mApkFile = apkFile;
mManifestUrl = manifestUrl;
Assert.isNotNull(mManifestUrl);
Assert.isTrue(mApkFile != null && mApkFile.exists());
if (mManifestUrl == null) {
throw new IllegalArgumentException("manifestUrl must not be null");
}
if (mApkFile == null || mApkFile.exists()) {
throw new IllegalArgumentException("apkFile must not be null and must exist");
}
}
public boolean isReceived() {

Просмотреть файл

@ -202,7 +202,6 @@ gbjar.sources += ['java/org/mozilla/gecko/' + x for x in [
'animation/ViewHelper.java',
'ANRReporter.java',
'AppNotificationClient.java',
'Assert.java',
'BaseGeckoInterface.java',
'BrowserApp.java',
'BrowserLocaleManager.java',