...
The Java SE 7 Documentation [J2SE 2011] defines Files.delete()
to throw the following exceptions:
Exception | Reason |
---|---|
| File does not exist |
| File is a directory and could not otherwise be deleted because the directory is not empty |
| An I/O error occurs |
| In the case of the default provider and a security manager is installed, the |
Because SecurityException
is a runtime exception, it need not be declared. Because NoSuchFileException
and DirectoryNotExmptyException
both inherit from IOException
, they will be caught by the compliant solution's catch
clause.
...
Failure to check the return values of methods that perform file I/O can result in unexpected behavior.
Rule | Severity | Likelihood | Remediation Cost | Priority | Level |
---|---|---|---|---|---|
FIO02-J | Medium | Probable | Medium | P8 | L2 |
Automated Detection
Tool | Version | Checker | Description | ||||||
---|---|---|---|---|---|---|---|---|---|
CodeSonar |
| JAVA.FUNCS.IRV | Ignored Return Value (Java) | ||||||
SonarQube |
| S899 |
Related Guidelines
Bibliography
[API 2014] |
|
| |
Chapter 8, "File I/O" |
...
...