Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get rid of Android Studio warning "Result of getException() not thrown"?

I have the following method:

private void recoverPassword() {

    FirebaseAuth mAuth = FirebaseAuth.getInstance();        

    mAuth.sendPasswordResetEmail("[email protected]").addOnCompleteListener(new OnCompleteListener<Void>() {

        @Override
        public void onComplete(@NonNull Task<Void> task) {
            if (!task.isSuccessful()) {
                Exception e = task.getException();
                System.out.println(e.toString());
        }
    });

}

And I keep getting Android Studio warning:

Result of 'getException()' not thrown

How can I rewrite the snippet above to get rid of that warning?

Thanks!

like image 332
Ramiro Avatar asked Jul 18 '16 01:07

Ramiro


1 Answers

Add a SuppressWarnings annotation to the method:

        @SuppressWarnings("ThrowableResultOfMethodCallIgnored")
        @Override
        public void onComplete(@NonNull Task<Void> task) {
            if (!task.isSuccessful()) {
                Exception e = task.getException();
                System.out.println(e.toString());
            }
        }

Android Studio will help you with this:

  1. Place the cursor on getException()
  2. Type Alt-Enter
  3. Click on Inspection 'Throwable result of method call ignored' options
  4. Click on Suppress for Method (or any other option you prefer)
like image 180
Bob Snyder Avatar answered Oct 26 '22 17:10

Bob Snyder