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

I have the following method:

private void recoverPassword() { FirebaseAuth mAuth = FirebaseAuth.getInstance(); mAuth.sendPasswordResetEmail("mail@example.com").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 warnings from Android Studio:

The result of 'getException ()' is not thrown

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

Thanks!

+8
android android-studio firebase firebase-authentication
source share
1 answer

Add the 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:

  • Place the cursor on getException()
  • Type Alt-Enter
  • Click Inspection 'Throwable result of method call ignored' options
  • Click Suppress for Method (or any other option you prefer)
+8
source share

All Articles