...
This noncompliant examples is designed to rename a given file if it is present, perform operations on it and then delete it. It can be deceptive that However, the renameTo()
method will not execute when the exists()
method returns true
, and an unsuspecting developer would incorrectly attempt to delete the new non-existent fNew
file instead of the original one. This problem is exacerbated by the fact that File.delete()
does not throw an exception but returns an error code on failure, which is often silently ignored or perceived as unnecessary. (See EXP02-J. Do not ignore values returned by methods)
...