Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c10230bd authored by William Escande's avatar William Escande
Browse files

ErrorProne: Enforce & fix CatchFail

See https://errorprone.info/bugpattern/CatchFail

Bug: 344658662
Test: m BluetoothInstrumentationTests
Flag: Exempt Build and test only
Change-Id: Ie4273ac932be0f33684b87da1d8c7d2610f3f20d
parent 9f3a6f32
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -58,6 +58,7 @@ java_defaults {
        enabled: true,
        javacflags: [
            "-Xep:AlmostJavadoc:ERROR",
            "-Xep:CatchFail:ERROR",
            "-Xep:EmptyCatch:ERROR",
            "-Xep:InvalidInlineTag:ERROR",
            "-Xep:NonApiType:ERROR",
+1 −6
Original line number Diff line number Diff line
@@ -23,7 +23,6 @@ import static com.google.common.truth.Truth.assertThat;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.after;
@@ -297,11 +296,7 @@ public class BatteryStateMachineTest {
        allowConnection(true);
        allowConnectGatt(true);

        try {
        mBatteryStateMachine.updateBatteryLevel(new byte[0]);
        } catch (Exception ex) {
            fail();
        }

        verify(mBatteryService, after(WAIT_MS).never())
                .handleBatteryChanged(any(BluetoothDevice.class), anyInt());
+12 −23
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.bluetooth.map;

import static org.junit.Assert.assertThrows;
import static org.mockito.Mockito.*;

import android.app.Activity;
@@ -64,7 +65,6 @@ import org.mockito.Spy;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.util.Calendar;
@@ -202,7 +202,7 @@ public class BluetoothMapContentObserverTest {
    }

    @Test
    public void testPushGroupMMS() {
    public void testPushGroupMMS() throws RemoteException {
        if (Looper.myLooper() == null) {
            Looper.prepare();
        }
@@ -216,31 +216,20 @@ public class BluetoothMapContentObserverTest {
        message.addRecipient("One", new String[] {TEST_NUMBER_ONE}, null);
        message.addRecipient("Two", new String[] {TEST_NUMBER_TWO}, null);
        BluetoothMapbMessageMime.MimePart body = message.addMimePart();
        try {

        body.mContentType = "text/plain";
            body.mData = "HelloWorld".getBytes("utf-8");
        } catch (Exception e) {
            Assert.fail("Failed to setup test message");
        }
        body.mData = "HelloWorld".getBytes(java.nio.charset.StandardCharsets.UTF_8);

        BluetoothMapAppParams appParams = new BluetoothMapAppParams();
        BluetoothMapFolderElement folderElement = new BluetoothMapFolderElement("outbox", null);

        try {
            // The constructor of BluetoothMapContentObserver calls initMsgList
        BluetoothMapContentObserver observer =
                new BluetoothMapContentObserver(mContext, null, mInstance, null, true);
            observer.pushMessage(message, folderElement, appParams, null);
        } catch (RemoteException e) {
            Assert.fail("Failed to created BluetoothMapContentObserver object");
        } catch (SQLiteException e) {
            Assert.fail("Threw SQLiteException instead of Assert.failing cleanly");
        } catch (IOException e) {
            Assert.fail("Threw IOException");
        } catch (NullPointerException e) {
            // expected that the test case will end in a NPE as part of the sendMultimediaMessage
            // pendingSendIntent
        }

        // The test end in a NPE as part of the sendMultimediaMessage pendingSendIntent
        assertThrows(
                NullPointerException.class,
                () -> observer.pushMessage(message, folderElement, appParams, null));

        // Validate that 3 addresses were inserted into the database with 2 being the recipients
        Assert.assertEquals(3, mProvider.mContents.size());
+3 −7
Original line number Diff line number Diff line
@@ -116,13 +116,9 @@ public class MediaControlProfileTest {
        doReturn(packageName).when(mMockMcpService).getPackageName();
        doReturn(name).when(mMockMediaPlayerWrapper).getPackageName();
        doReturn(charSequence).when(mMockApplicationInfo).loadLabel(any(PackageManager.class));
        try {
        doReturn(mMockApplicationInfo)
                .when(mMockPackageManager)
                .getApplicationInfo(anyString(), anyInt());
        } catch (PackageManager.NameNotFoundException e) {
            Assert.fail();
        }

        mPendingStateRequest = new ArrayList<>();

+1 −0
Original line number Diff line number Diff line
@@ -91,6 +91,7 @@ java_sdk_library {
        javacflags: [
            "-Xep:InlineMeSuggester:OFF", // The @InlineMe annotation is not available

            "-Xep:CatchFail:ERROR",
            "-Xep:EmptyCatch:ERROR",
            "-Xep:InvalidInlineTag:ERROR",
            "-Xep:NonApiType:ERROR",
Loading