Commit a238881c authored by Tomasz Wiszkowski's avatar Tomasz Wiszkowski Committed by Commit Bot

Enable errorprone compile-time nullable checks.

This change enables errorprone basic null checking.
The new flag will raise an error when a @Nullable
argument or variable is not checked before being used.

The code updates all sites that declared parameters as
@Nullable without subsequently checking their values to
@NonNull.

The change should help push forward the effort to enable
the NullAway errorprone extension

Bug: 1022427

Change-Id: I6c1e87d87fad98252c3cc3916e3a1034cf4eb8cc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2521294
Commit-Queue: Tomasz Wiszkowski <ender@google.com>
Reviewed-by: default avatarDavid Trainor <dtrainor@chromium.org>
Reviewed-by: default avatarTed Choc <tedchoc@chromium.org>
Reviewed-by: default avatarXing Liu <xingliu@chromium.org>
Reviewed-by: default avatarAndrew Grieve <agrieve@chromium.org>
Cr-Commit-Position: refs/heads/master@{#825008}
parent 553c38ae
...@@ -32,7 +32,6 @@ _JAVAC_EXTRACTOR = os.path.join(build_utils.DIR_SOURCE_ROOT, 'third_party', ...@@ -32,7 +32,6 @@ _JAVAC_EXTRACTOR = os.path.join(build_utils.DIR_SOURCE_ROOT, 'third_party',
# Full list of checks: https://errorprone.info/bugpatterns # Full list of checks: https://errorprone.info/bugpatterns
ERRORPRONE_WARNINGS_TO_DISABLE = [ ERRORPRONE_WARNINGS_TO_DISABLE = [
# These should really be turned on. # These should really be turned on.
'ParameterNotNullable',
'CollectionUndefinedEquality', 'CollectionUndefinedEquality',
'ModifyCollectionInEnhancedForLoop', 'ModifyCollectionInEnhancedForLoop',
# The following are super useful, but existing issues need to be fixed first # The following are super useful, but existing issues need to be fixed first
...@@ -183,6 +182,7 @@ ERRORPRONE_WARNINGS_TO_ENABLE = [ ...@@ -183,6 +182,7 @@ ERRORPRONE_WARNINGS_TO_ENABLE = [
'InvalidThrows', 'InvalidThrows',
'LongLiteralLowerCaseSuffix', 'LongLiteralLowerCaseSuffix',
'MultiVariableDeclaration', 'MultiVariableDeclaration',
'ParameterNotNullable',
'RedundantOverride', 'RedundantOverride',
'StaticQualifiedUsingExpression', 'StaticQualifiedUsingExpression',
'StringEquality', 'StringEquality',
......
...@@ -13,6 +13,7 @@ import android.view.ViewGroup; ...@@ -13,6 +13,7 @@ import android.view.ViewGroup;
import android.widget.TextView; import android.widget.TextView;
import androidx.annotation.DrawableRes; import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import org.chromium.chrome.autofill_assistant.R; import org.chromium.chrome.autofill_assistant.R;
...@@ -32,7 +33,7 @@ public class AssistantLoginSection extends AssistantCollectUserDataSection<Assis ...@@ -32,7 +33,7 @@ public class AssistantLoginSection extends AssistantCollectUserDataSection<Assis
} }
@Override @Override
protected void createOrEditItem(@Nullable AssistantLoginChoice oldItem) { protected void createOrEditItem(@NonNull AssistantLoginChoice oldItem) {
assert oldItem != null; assert oldItem != null;
assert oldItem.getInfoPopup() != null; assert oldItem.getInfoPopup() != null;
......
...@@ -95,7 +95,7 @@ public final class ScreenshotTask implements ScreenshotSource { ...@@ -95,7 +95,7 @@ public final class ScreenshotTask implements ScreenshotSource {
} }
private boolean takeCompositorScreenshot(@Nullable Activity activity) { private boolean takeCompositorScreenshot(@Nullable Activity activity) {
if (!shouldTakeCompositorScreenshot((activity))) return false; if (activity == null || !shouldTakeCompositorScreenshot((activity))) return false;
Rect rect = new Rect(); Rect rect = new Rect();
activity.getWindow().getDecorView().getRootView().getWindowVisibleDisplayFrame(rect); activity.getWindow().getDecorView().getRootView().getWindowVisibleDisplayFrame(rect);
......
...@@ -21,7 +21,7 @@ public final class TitleUtil { ...@@ -21,7 +21,7 @@ public final class TitleUtil {
* it. Otherwise, returns a shortened form of the URL. * it. Otherwise, returns a shortened form of the URL.
*/ */
public static String getTitleForDisplay(@Nullable String title, @Nullable GURL url) { public static String getTitleForDisplay(@Nullable String title, @Nullable GURL url) {
if (!TextUtils.isEmpty(title) || GURL.isEmptyOrInvalid(url)) { if (!TextUtils.isEmpty(title) || url == null || GURL.isEmptyOrInvalid(url)) {
return title; return title;
} }
......
...@@ -168,19 +168,19 @@ public class AddressEditor ...@@ -168,19 +168,19 @@ public class AddressEditor
// If |toEdit| is null, we're creating a new autofill profile with the country code of the // If |toEdit| is null, we're creating a new autofill profile with the country code of the
// default locale on this device. // default locale on this device.
boolean isNewAddress = toEdit == null; final String editTitle;
final AutofillAddress address;
if (toEdit == null) {
address = new AutofillAddress(mContext, new AutofillProfile());
editTitle = mContext.getString(R.string.autofill_create_profile);
} else {
address = toEdit;
editTitle = toEdit.getEditTitle();
}
// Ensure that |address| and |mProfile| are always not null. mEditor = new EditorModel(editTitle);
final AutofillAddress address =
isNewAddress ? new AutofillAddress(mContext, new AutofillProfile()) : toEdit;
mProfile = address.getProfile(); mProfile = address.getProfile();
// The title of the editor depends on whether we're adding a new address or editing an
// existing address.
mEditor =
new EditorModel(isNewAddress ? mContext.getString(R.string.autofill_create_profile)
: toEdit.getEditTitle());
// When edit is called, a new form is started, so the country on the // When edit is called, a new form is started, so the country on the
// dropdown list is not changed. => mRecentlySelectedCountry should be null. // dropdown list is not changed. => mRecentlySelectedCountry should be null.
mRecentlySelectedCountry = null; mRecentlySelectedCountry = null;
......
...@@ -352,19 +352,24 @@ public class CardEditor extends EditorBase<AutofillPaymentInstrument> ...@@ -352,19 +352,24 @@ public class CardEditor extends EditorBase<AutofillPaymentInstrument>
final Callback<AutofillPaymentInstrument> cancelCallback) { final Callback<AutofillPaymentInstrument> cancelCallback) {
super.edit(toEdit, doneCallback, cancelCallback); super.edit(toEdit, doneCallback, cancelCallback);
// If |toEdit| is null, we're creating a new credit card. final boolean isNewCard;
final boolean isNewCard = toEdit == null; final AutofillPaymentInstrument instrument;
final EditorModel editor;
// Ensure that |instrument| and |card| are never null.
final AutofillPaymentInstrument instrument = isNewCard if (toEdit == null) {
? new AutofillPaymentInstrument(mWebContents, new CreditCard(), // We're creating a new credit card.
null /* billingAddress */, null /* methodName */) isNewCard = true;
: toEdit; // Ensure that |instrument| is never null.
final CreditCard card = instrument.getCard(); instrument = new AutofillPaymentInstrument(mWebContents, new CreditCard(),
null /* billingAddress */, null /* methodName */);
final EditorModel editor = new EditorModel( editor = new EditorModel(mContext.getString(R.string.payments_add_card));
isNewCard ? mContext.getString(R.string.payments_add_card) : toEdit.getEditTitle()); } else {
isNewCard = false;
instrument = toEdit;
editor = new EditorModel(toEdit.getEditTitle());
}
final CreditCard card = instrument.getCard();
if (card.getIsLocal()) { if (card.getIsLocal()) {
Calendar calendar = null; Calendar calendar = null;
try { try {
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
package org.chromium.chrome.browser.webapps; package org.chromium.chrome.browser.webapps;
import androidx.annotation.Nullable; import androidx.annotation.NonNull;
import org.chromium.chrome.browser.app.ChromeActivity; import org.chromium.chrome.browser.app.ChromeActivity;
import org.chromium.chrome.browser.browserservices.ui.controller.webapps.WebappDisclosureController; import org.chromium.chrome.browser.browserservices.ui.controller.webapps.WebappDisclosureController;
...@@ -49,7 +49,7 @@ public class WebApkActivityCoordinator implements Destroyable { ...@@ -49,7 +49,7 @@ public class WebApkActivityCoordinator implements Destroyable {
} }
public void onDeferredStartupWithStorage( public void onDeferredStartupWithStorage(
@Nullable WebappDataStorage storage, boolean didCreateStorage) { @NonNull WebappDataStorage storage, boolean didCreateStorage) {
assert storage != null; assert storage != null;
storage.incrementLaunchCount(); storage.incrementLaunchCount();
......
...@@ -96,6 +96,7 @@ public class TrustedWebActivityClientLocationDelegationTest { ...@@ -96,6 +96,7 @@ public class TrustedWebActivityClientLocationDelegationTest {
@Override @Override
public void onExtraCallback(String callbackName, @Nullable Bundle bundle) { public void onExtraCallback(String callbackName, @Nullable Bundle bundle) {
if (TextUtils.equals(callbackName, EXTRA_NEW_LOCATION_AVAILABLE_CALLBACK)) { if (TextUtils.equals(callbackName, EXTRA_NEW_LOCATION_AVAILABLE_CALLBACK)) {
Assert.assertNotNull(bundle);
Assert.assertTrue(bundle.containsKey("latitude")); Assert.assertTrue(bundle.containsKey("latitude"));
Assert.assertTrue(bundle.containsKey("longitude")); Assert.assertTrue(bundle.containsKey("longitude"));
Assert.assertTrue(bundle.containsKey("timeStamp")); Assert.assertTrue(bundle.containsKey("timeStamp"));
...@@ -123,6 +124,7 @@ public class TrustedWebActivityClientLocationDelegationTest { ...@@ -123,6 +124,7 @@ public class TrustedWebActivityClientLocationDelegationTest {
@Override @Override
public void onExtraCallback(String callbackName, @Nullable Bundle bundle) { public void onExtraCallback(String callbackName, @Nullable Bundle bundle) {
if (TextUtils.equals(callbackName, EXTRA_NEW_LOCATION_ERROR_CALLBACK)) { if (TextUtils.equals(callbackName, EXTRA_NEW_LOCATION_ERROR_CALLBACK)) {
Assert.assertNotNull(bundle);
Assert.assertTrue(bundle.containsKey("message")); Assert.assertTrue(bundle.containsKey("message"));
locationError.notifyCalled(); locationError.notifyCalled();
} }
......
...@@ -7,7 +7,7 @@ package org.chromium.chrome.browser.download.dialogs; ...@@ -7,7 +7,7 @@ package org.chromium.chrome.browser.download.dialogs;
import android.content.Context; import android.content.Context;
import androidx.annotation.IntDef; import androidx.annotation.IntDef;
import androidx.annotation.Nullable; import androidx.annotation.NonNull;
import org.chromium.base.Callback; import org.chromium.base.Callback;
import org.chromium.chrome.browser.download.DownloadLaterMetrics; import org.chromium.chrome.browser.download.DownloadLaterMetrics;
...@@ -71,14 +71,12 @@ public class DownloadLaterDialogHelper implements DownloadLaterDialogController ...@@ -71,14 +71,12 @@ public class DownloadLaterDialogHelper implements DownloadLaterDialogController
* @param callback The callback to reply the new schedule selected by the user. May reply null * @param callback The callback to reply the new schedule selected by the user. May reply null
* if the user cancels the dialog. * if the user cancels the dialog.
*/ */
public void showChangeScheduleDialog(@Nullable final OfflineItemSchedule currentSchedule, public void showChangeScheduleDialog(@NonNull final OfflineItemSchedule currentSchedule,
@Source int source, Callback<OfflineItemSchedule> callback) { @Source int source, Callback<OfflineItemSchedule> callback) {
@DownloadLaterDialogChoice @DownloadLaterDialogChoice
int initialChoice = DownloadLaterDialogChoice.DOWNLOAD_NOW; int initialChoice = DownloadLaterDialogChoice.DOWNLOAD_NOW;
if (currentSchedule != null) { initialChoice = currentSchedule.onlyOnWifi ? DownloadLaterDialogChoice.ON_WIFI
initialChoice = currentSchedule.onlyOnWifi ? DownloadLaterDialogChoice.ON_WIFI : DownloadLaterDialogChoice.DOWNLOAD_LATER;
: DownloadLaterDialogChoice.DOWNLOAD_LATER;
}
mCallback = callback; mCallback = callback;
mSource = source; mSource = source;
......
...@@ -92,7 +92,7 @@ public final class EditorScreenshotTask implements EditorScreenshotSource { ...@@ -92,7 +92,7 @@ public final class EditorScreenshotTask implements EditorScreenshotSource {
} }
private boolean takeCompositorScreenshot(@Nullable Activity activity) { private boolean takeCompositorScreenshot(@Nullable Activity activity) {
if (!shouldTakeCompositorScreenshot((activity))) return false; if (activity == null || !shouldTakeCompositorScreenshot((activity))) return false;
Rect rect = new Rect(); Rect rect = new Rect();
activity.getWindow().getDecorView().getRootView().getWindowVisibleDisplayFrame(rect); activity.getWindow().getDecorView().getRootView().getWindowVisibleDisplayFrame(rect);
......
...@@ -19,6 +19,7 @@ import androidx.annotation.Nullable; ...@@ -19,6 +19,7 @@ import androidx.annotation.Nullable;
import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentManager;
import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
...@@ -60,6 +61,7 @@ public class ScreenshotCoordinatorTest { ...@@ -60,6 +61,7 @@ public class ScreenshotCoordinatorTest {
@Override @Override
public void capture(@Nullable Runnable callback) { public void capture(@Nullable Runnable callback) {
Assert.assertNotNull(callback);
callback.run(); callback.run();
} }
......
...@@ -1225,7 +1225,7 @@ class BottomSheet extends FrameLayout ...@@ -1225,7 +1225,7 @@ class BottomSheet extends FrameLayout
protected void onSheetContentChanged(@Nullable final BottomSheetContent content) { protected void onSheetContentChanged(@Nullable final BottomSheetContent content) {
mSheetContent = content; mSheetContent = content;
if (isFullHeightWrapContent()) { if (content != null && isFullHeightWrapContent()) {
// Listen for layout/size changes. // Listen for layout/size changes.
if (!content.setContentSizeListener(this::onContentSizeChanged)) { if (!content.setContentSizeListener(this::onContentSizeChanged)) {
content.getContentView().addOnLayoutChangeListener(this); content.getContentView().addOnLayoutChangeListener(this);
......
...@@ -7,6 +7,7 @@ package org.chromium.components.browser_ui.contacts_picker; ...@@ -7,6 +7,7 @@ package org.chromium.components.browser_ui.contacts_picker;
import android.content.res.Resources; import android.content.res.Resources;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import org.chromium.blink.mojom.ContactIconBlob; import org.chromium.blink.mojom.ContactIconBlob;
...@@ -227,7 +228,7 @@ public class ContactDetails implements Comparable<ContactDetails> { ...@@ -227,7 +228,7 @@ public class ContactDetails implements Comparable<ContactDetails> {
* @return The contact details registered for this contact. * @return The contact details registered for this contact.
*/ */
public AbbreviatedContactDetails getAbbreviatedContactDetails(boolean includeAddresses, public AbbreviatedContactDetails getAbbreviatedContactDetails(boolean includeAddresses,
boolean includeEmails, boolean includeTels, @Nullable Resources resources) { boolean includeEmails, boolean includeTels, @NonNull Resources resources) {
AbbreviatedContactDetails results = new AbbreviatedContactDetails(); AbbreviatedContactDetails results = new AbbreviatedContactDetails();
results.overflowAddressCount = ""; results.overflowAddressCount = "";
......
...@@ -8,6 +8,7 @@ import android.app.Activity; ...@@ -8,6 +8,7 @@ import android.app.Activity;
import android.content.ComponentName; import android.content.ComponentName;
import android.net.Uri; import android.net.Uri;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import org.chromium.base.CollectionUtil; import org.chromium.base.CollectionUtil;
...@@ -159,7 +160,7 @@ public class ShareServiceImpl implements ShareService { ...@@ -159,7 +160,7 @@ public class ShareServiceImpl implements ShareService {
public void share(ShareParams params); public void share(ShareParams params);
} }
public ShareServiceImpl(@Nullable WebContents webContents, WebShareDelegate delegate) { public ShareServiceImpl(@NonNull WebContents webContents, WebShareDelegate delegate) {
mWindow = webContents.getTopLevelNativeWindow(); mWindow = webContents.getTopLevelNativeWindow();
mDelegate = delegate; mDelegate = delegate;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment