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

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

Posted by: admin June 15, 2020 Leave a comment

Questions:

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!

How to&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)