Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Findbugs - Method ignores exceptional return value

Tags:

findbugs

I am getting below Findbugs error for my below code. please let me know what needs to do for this?

Code:

public void myMethod(Key key, long timestampMillis) {
        File file = createFile(key, timestampMillis);
        boolean deleted = file.delete();
    }

<<Package/classname>> ignores exceptional return value of java.io.File.delete() This method returns a value that is not checked. The return value should be checked since it can indicate an unusual or unexpected function execution. For example, the File.delete() method returns false if the file could not be successfully deleted (rather than throwing an Exception). If you don't check the result, you won't notice if the method invocation signals unexpected behavior by returning an atypical return value.

like image 434
Srinivasan Avatar asked Jul 20 '11 05:07

Srinivasan


1 Answers

It's just letting you know that you're getting the output of file.delete() and then throwing it away. If you need to know if the delete succeeded, then do something with the deleted variable, otherwise your code is fine.

like image 145
Jon7 Avatar answered Sep 23 '22 15:09

Jon7