Bug 1081599: Don't check nullity before instanceof. r=rnewman
authorChris Kitching <chriskitching@linux.com>
Sun, 12 Oct 2014 02:14:10 +0100
changeset 233214 0dc0ff9bb484b2782786bdc4ee73be80f5048ab6
parent 233213 0fcf464736d797534db58fbd5266f350c3ef42cf
child 233215 e811af3754be45b84846faf3a4076d82b3b5a9e3
push id4187
push userbhearsum@mozilla.com
push dateFri, 28 Nov 2014 15:29:12 +0000
treeherdermozilla-beta@f23cc6a30c11 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrnewman
bugs1081599
milestone35.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1081599: Don't check nullity before instanceof. r=rnewman * * * Bug 1081599: Don't check nullity before instanceof. r=rnewman
mobile/android/base/GeckoApp.java
mobile/android/base/LightweightTheme.java
mobile/android/base/NotificationHandler.java
mobile/android/base/background/healthreport/upload/ObsoleteDocumentTracker.java
mobile/android/base/home/HomeFragment.java
mobile/android/base/home/TopSitesPanel.java
mobile/android/base/preferences/ListCheckboxPreference.java
mobile/android/base/sync/ExtendedJSONObject.java
mobile/android/base/sync/repositories/domain/BookmarkRecord.java
mobile/android/base/sync/repositories/domain/FormHistoryRecord.java
mobile/android/base/sync/repositories/domain/HistoryRecord.java
mobile/android/base/sync/repositories/domain/PasswordRecord.java
mobile/android/base/sync/repositories/domain/Record.java
mobile/android/base/widget/TwoWayView.java
--- a/mobile/android/base/GeckoApp.java
+++ b/mobile/android/base/GeckoApp.java
@@ -1746,17 +1746,17 @@ public abstract class GeckoApp
                         listener.onOrientationChanged();
                     }
                 }
             }
         };
         mCameraOrientationEventListener.enable();
 
         // Try to make it fully transparent.
-        if (mCameraView != null && (mCameraView instanceof SurfaceView)) {
+        if (mCameraView instanceof SurfaceView) {
             if (Versions.feature11Plus) {
                 mCameraView.setAlpha(0.0f);
             }
             ViewGroup mCameraLayout = (ViewGroup) findViewById(R.id.camera_layout);
             // Some phones (eg. nexus S) need at least a 8x16 preview size
             mCameraLayout.addView(mCameraView,
                                   new AbsoluteLayout.LayoutParams(8, 16, 0, 0));
         }
--- a/mobile/android/base/LightweightTheme.java
+++ b/mobile/android/base/LightweightTheme.java
@@ -338,17 +338,17 @@ public class LightweightTheme implements
             }
 
             parent = curView.getParent();
 
             if (parent instanceof View) {
                 curView = (View) parent;
             }
 
-        } while(parent instanceof View && parent != null);
+        } while(parent instanceof View);
 
         // Adjust the coordinates for the offset.
         left -= offsetX;
         right -= offsetX;
         top -= offsetY;
         bottom -= offsetY;
 
         // The either the required height may be less than the available image height or more than it.
--- a/mobile/android/base/NotificationHandler.java
+++ b/mobile/android/base/NotificationHandler.java
@@ -157,17 +157,17 @@ public class NotificationHandler {
     /**
      * Helper method to determines whether a notification is an AlertNotification that is showing progress
      * This method will be deprecated when AlertNotifications are removed (bug 893289). 
      *
      * @param notification   the notification to check
      * @return               whether the notification is an AlertNotification showing progress.
      */
     private boolean isProgressStyle(Notification notification) {
-        if (notification != null && notification instanceof AlertNotification) {
+        if (notification instanceof AlertNotification) {
             return ((AlertNotification)notification).isProgressStyle();
         }
         return false;
     }
 
     protected void setForegroundNotification(int id, Notification notification) {
         mForegroundNotificationId = id;
         mForegroundNotification = notification;
--- a/mobile/android/base/background/healthreport/upload/ObsoleteDocumentTracker.java
+++ b/mobile/android/base/background/healthreport/upload/ObsoleteDocumentTracker.java
@@ -126,23 +126,23 @@ public class ObsoleteDocumentTracker {
    *
    * Public for testing only.
    */
   public static class PairComparator implements Comparator<Entry<String, Object>> {
     @Override
     public int compare(Entry<String, Object> lhs, Entry<String, Object> rhs) {
       Object l = lhs.getValue();
       Object r = rhs.getValue();
-      if (l == null || !(l instanceof Long)) {
-        if (r == null || !(r instanceof Long)) {
+      if (!(l instanceof Long)) {
+        if (!(r instanceof Long)) {
           return 0;
         }
         return -1;
       }
-      if (r == null || !(r instanceof Long)) {
+      if (!(r instanceof Long)) {
         return 1;
       }
       return ((Long) r).compareTo((Long) l);
     }
   }
 
   /**
    * Return a batch of obsolete document IDs that should be deleted next.
--- a/mobile/android/base/home/HomeFragment.java
+++ b/mobile/android/base/home/HomeFragment.java
@@ -111,17 +111,17 @@ public abstract class HomeFragment exten
             mCanLoadHint = DEFAULT_CAN_LOAD_HINT;
         }
 
         mIsLoaded = false;
     }
 
     @Override
     public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo menuInfo) {
-        if (menuInfo == null || !(menuInfo instanceof HomeContextMenuInfo)) {
+        if (!(menuInfo instanceof HomeContextMenuInfo)) {
             return;
         }
 
         HomeContextMenuInfo info = (HomeContextMenuInfo) menuInfo;
 
         // Don't show the context menu for folders.
         if (info.isFolder) {
             return;
@@ -156,17 +156,17 @@ public abstract class HomeFragment exten
     @Override
     public boolean onContextItemSelected(MenuItem item) {
         // onContextItemSelected() is first dispatched to the activity and
         // then dispatched to its fragments. Since fragments cannot "override"
         // menu item selection handling, it's better to avoid menu id collisions
         // between the activity and its fragments.
 
         ContextMenuInfo menuInfo = item.getMenuInfo();
-        if (menuInfo == null || !(menuInfo instanceof HomeContextMenuInfo)) {
+        if (!(menuInfo instanceof HomeContextMenuInfo)) {
             return false;
         }
 
         final HomeContextMenuInfo info = (HomeContextMenuInfo) menuInfo;
         final Context context = getActivity();
 
         final int itemId = item.getItemId();
 
--- a/mobile/android/base/home/TopSitesPanel.java
+++ b/mobile/android/base/home/TopSitesPanel.java
@@ -279,17 +279,17 @@ public class TopSitesPanel extends HomeF
     public boolean onContextItemSelected(MenuItem item) {
         if (super.onContextItemSelected(item)) {
             // HomeFragment was able to handle to selected item.
             return true;
         }
 
         ContextMenuInfo menuInfo = item.getMenuInfo();
 
-        if (menuInfo == null || !(menuInfo instanceof TopSitesGridContextMenuInfo)) {
+        if (!(menuInfo instanceof TopSitesGridContextMenuInfo)) {
             return false;
         }
 
         TopSitesGridContextMenuInfo info = (TopSitesGridContextMenuInfo) menuInfo;
 
         final int itemId = item.getItemId();
 
         if (itemId == R.id.top_sites_pin) {
--- a/mobile/android/base/preferences/ListCheckboxPreference.java
+++ b/mobile/android/base/preferences/ListCheckboxPreference.java
@@ -31,17 +31,17 @@ class ListCheckboxPreference extends Mul
         return checked;
     }
 
     @Override
     protected void onBindView(View view) {
         super.onBindView(view);
 
         View checkboxView = view.findViewById(R.id.checkbox);
-        if (checkboxView != null && checkboxView instanceof Checkable) {
+        if (checkboxView instanceof Checkable) {
             ((Checkable) checkboxView).setChecked(checked);
         }
     }
 
     @Override
     public void setChecked(boolean checked) {
         boolean changed = checked != this.checked;
         this.checked = checked;
--- a/mobile/android/base/sync/ExtendedJSONObject.java
+++ b/mobile/android/base/sync/ExtendedJSONObject.java
@@ -337,17 +337,17 @@ public class ExtendedJSONObject {
     if (this.object == null) {
       return getClass().hashCode();
     }
     return this.object.hashCode() ^ getClass().hashCode();
   }
 
   @Override
   public boolean equals(Object o) {
-    if (o == null || !(o instanceof ExtendedJSONObject)) {
+    if (!(o instanceof ExtendedJSONObject)) {
       return false;
     }
     if (o == this) {
       return true;
     }
     ExtendedJSONObject other = (ExtendedJSONObject) o;
     if (this.object == null) {
       return other.object == null;
--- a/mobile/android/base/sync/repositories/domain/BookmarkRecord.java
+++ b/mobile/android/base/sync/repositories/domain/BookmarkRecord.java
@@ -312,17 +312,17 @@ public class BookmarkRecord extends Reco
 
   private void trace(String s) {
     Logger.trace(LOG_TAG, s);
   }
 
   @Override
   public boolean equalPayloads(Object o) {
     trace("Calling BookmarkRecord.equalPayloads.");
-    if (o == null || !(o instanceof BookmarkRecord)) {
+    if (!(o instanceof BookmarkRecord)) {
       return false;
     }
 
     BookmarkRecord other = (BookmarkRecord) o;
     if (!super.equalPayloads(other)) {
       return false;
     }
 
--- a/mobile/android/base/sync/repositories/domain/FormHistoryRecord.java
+++ b/mobile/android/base/sync/repositories/domain/FormHistoryRecord.java
@@ -81,30 +81,30 @@ public class FormHistoryRecord extends R
   }
 
   /**
    * We consider two form history records to be congruent if they represent the
    * same form element regardless of times used.
    */
   @Override
   public boolean congruentWith(Object o) {
-    if (o == null || !(o instanceof FormHistoryRecord)) {
+    if (!(o instanceof FormHistoryRecord)) {
       return false;
     }
     FormHistoryRecord other = (FormHistoryRecord) o;
     if (!super.congruentWith(other)) {
       return false;
     }
     return RepoUtils.stringsEqual(this.fieldName, other.fieldName) &&
            RepoUtils.stringsEqual(this.fieldValue, other.fieldValue);
   }
 
   @Override
   public boolean equalPayloads(Object o) {
-    if (o == null || !(o instanceof FormHistoryRecord)) {
+    if (!(o instanceof FormHistoryRecord)) {
       Logger.debug(LOG_TAG, "Not a FormHistoryRecord: " + o.getClass());
       return false;
     }
     FormHistoryRecord other = (FormHistoryRecord) o;
     if (!super.equalPayloads(other)) {
       Logger.debug(LOG_TAG, "super.equalPayloads returned false.");
       return false;
     }
--- a/mobile/android/base/sync/repositories/domain/HistoryRecord.java
+++ b/mobile/android/base/sync/repositories/domain/HistoryRecord.java
@@ -98,29 +98,29 @@ public class HistoryRecord extends Recor
 
   /**
    * We consider two history records to be congruent if they represent the
    * same history record regardless of visits. Titles are allowed to differ,
    * but the URI must be the same.
    */
   @Override
   public boolean congruentWith(Object o) {
-    if (o == null || !(o instanceof HistoryRecord)) {
+    if (!(o instanceof HistoryRecord)) {
       return false;
     }
     HistoryRecord other = (HistoryRecord) o;
     if (!super.congruentWith(other)) {
       return false;
     }
     return RepoUtils.stringsEqual(this.histURI, other.histURI);
   }
 
   @Override
   public boolean equalPayloads(Object o) {
-    if (o == null || !(o instanceof HistoryRecord)) {
+    if (!(o instanceof HistoryRecord)) {
       Logger.debug(LOG_TAG, "Not a HistoryRecord: " + o.getClass());
       return false;
     }
     HistoryRecord other = (HistoryRecord) o;
     if (!super.equalPayloads(other)) {
       Logger.debug(LOG_TAG, "super.equalPayloads returned false.");
       return false;
     }
--- a/mobile/android/base/sync/repositories/domain/PasswordRecord.java
+++ b/mobile/android/base/sync/repositories/domain/PasswordRecord.java
@@ -105,17 +105,17 @@ public class PasswordRecord extends Reco
     putPayload(payload, PAYLOAD_USERNAME, this.encryptedUsername);
     putPayload(payload, PAYLOAD_PASSWORD, this.encryptedPassword);
     putPayload(payload, PAYLOAD_USERNAME_FIELD, this.usernameField);
     putPayload(payload, PAYLOAD_PASSWORD_FIELD, this.passwordField);
   }
 
   @Override
   public boolean congruentWith(Object o) {
-    if (o == null || !(o instanceof PasswordRecord)) {
+    if (!(o instanceof PasswordRecord)) {
       return false;
     }
     PasswordRecord other = (PasswordRecord) o;
     if (!super.congruentWith(other)) {
       return false;
     }
     return RepoUtils.stringsEqual(this.hostname, other.hostname)
         && RepoUtils.stringsEqual(this.formSubmitURL, other.formSubmitURL)
@@ -125,17 +125,17 @@ public class PasswordRecord extends Reco
         && RepoUtils.stringsEqual(this.usernameField, other.usernameField)
         && RepoUtils.stringsEqual(this.passwordField, other.passwordField)
         && RepoUtils.stringsEqual(this.encryptedUsername, other.encryptedUsername)
         && RepoUtils.stringsEqual(this.encryptedPassword, other.encryptedPassword);
   }
 
   @Override
   public boolean equalPayloads(Object o) {
-    if (o == null || !(o instanceof PasswordRecord)) {
+    if (!(o instanceof PasswordRecord)) {
       return false;
     }
 
     PasswordRecord other = (PasswordRecord) o;
     Logger.debug("PasswordRecord", "thisRecord:" + this.toString());
     Logger.debug("PasswordRecord", "otherRecord:" + o.toString());
 
     if (this.deleted) {
--- a/mobile/android/base/sync/repositories/domain/Record.java
+++ b/mobile/android/base/sync/repositories/domain/Record.java
@@ -97,17 +97,17 @@ public abstract class Record {
     this.androidID    = -1;
   }
 
   /**
    * Return true iff the input is a Record and has the same
    * collection and guid as this object.
    */
   public boolean equalIdentifiers(Object o) {
-    if (o == null || !(o instanceof Record)) {
+    if (!(o instanceof Record)) {
       return false;
     }
 
     Record other = (Record) o;
     if (this.guid == null) {
       if (other.guid != null) {
         return false;
       }
@@ -174,17 +174,17 @@ public abstract class Record {
   }
 
   /**
    * Return true iff the input is both equal in terms of payload,
    * and also shares transient values such as timestamps.
    */
   @Override
   public boolean equals(Object o) {
-    if (o == null || !(o instanceof Record)) {
+    if (!(o instanceof Record)) {
       return false;
     }
 
     Record other = (Record) o;
     return equalTimestamps(other) &&
            equalSortIndices(other) &&
            equalAndroidIDs(other) &&
            equalPayloads(o);
@@ -194,17 +194,17 @@ public abstract class Record {
     return this.androidID == other.androidID;
   }
 
   public boolean equalSortIndices(Record other) {
     return this.sortIndex == other.sortIndex;
   }
 
   public boolean equalTimestamps(Object o) {
-    if (o == null || !(o instanceof Record)) {
+    if (!(o instanceof Record)) {
       return false;
     }
     return ((Record) o).lastModified == this.lastModified;
   }
 
   protected abstract void populatePayload(ExtendedJSONObject payload);
   protected abstract void initFromPayload(ExtendedJSONObject payload);
 
--- a/mobile/android/base/widget/TwoWayView.java
+++ b/mobile/android/base/widget/TwoWayView.java
@@ -1500,17 +1500,17 @@ public class TwoWayView extends AdapterV
                             mTouchMode = TOUCH_MODE_TAP;
 
                             setPressed(true);
                             positionSelector(mMotionPosition, child);
                             child.setPressed(true);
 
                             if (mSelector != null) {
                                 Drawable d = mSelector.getCurrent();
-                                if (d != null && d instanceof TransitionDrawable) {
+                                if (d instanceof TransitionDrawable) {
                                     ((TransitionDrawable) d).resetTransition();
                                 }
                             }
 
                             if (mTouchModeReset != null) {
                                 removeCallbacks(mTouchModeReset);
                             }
 
@@ -3341,17 +3341,17 @@ public class TwoWayView extends AdapterV
 
                 child.setPressed(true);
             }
 
             setPressed(true);
 
             final boolean longClickable = isLongClickable();
             final Drawable d = selector.getCurrent();
-            if (d != null && d instanceof TransitionDrawable) {
+            if (d instanceof TransitionDrawable) {
                 if (longClickable) {
                     ((TransitionDrawable) d).startTransition(
                             ViewConfiguration.getLongPressTimeout());
                 } else {
                     ((TransitionDrawable) d).resetTransition();
                 }
             }
 
@@ -6252,17 +6252,17 @@ public class TwoWayView extends AdapterV
                     positionSelector(mMotionPosition, child);
                     refreshDrawableState();
 
                     final boolean longClickable = isLongClickable();
 
                     if (mSelector != null) {
                         Drawable d = mSelector.getCurrent();
 
-                        if (d != null && d instanceof TransitionDrawable) {
+                        if (d instanceof TransitionDrawable) {
                             if (longClickable) {
                                 final int longPressTimeout = ViewConfiguration.getLongPressTimeout();
                                 ((TransitionDrawable) d).startTransition(longPressTimeout);
                             } else {
                                 ((TransitionDrawable) d).resetTransition();
                             }
                         }
                     }