Java's file-manipulation functions often indicate failure with a return value rather than by throwing an exception. The Java Tutorial for Java 7 notes:
Prior to the Java SE 7 release, the
java.io.File
class was the mechanism used for file I/O, but it had several drawbacks.Many methods didn't throw exceptions when they failed, so it was impossible to obtain a useful error message. For example, if a file deletion failed, the program would receive a "delete fail" but wouldn't know if it was because the file didn't exist, the user didn't have permissions, or there was some other problem.
Consequently, programs that ignore the return values from file operations can silently fail if the methods' return values are ignoredoften fail to detect when those operations have failed. Java programs must check the return values of methods that perform file I/O (this is a specific instance of rule EXP00-J. Do not ignore values returned by methods).
...
Wiki Markup |
---|
This noncompliant code example attempts to delete a specified file but gives no indication of its success. The \[[API 2006|AA. Bibliography#API 06]\] requires {{File.delete()}} to only throw a {{SecurityException}} only ifwhen the program islacks notauthorization authorized to delete the file. No other exceptions are thrown, so the deletion can silently fail. |
...
Rule | Severity | Likelihood | Remediation Cost | Priority | Level |
---|---|---|---|---|---|
FIO02-J | medium | probable | high | P4 | L3 |
Automated Detection
TODO
Related Guidelines
...
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="be7ec95ddf3a5f2b-80a51cc9-45474546-9769b6f2-e8bd95b9a3027fb55cf470d3"><ac:plain-text-body><![CDATA[ | [[API 2006 | AA. Bibliography#API 06]] | | ]]></ac:plain-text-body></ac:structured-macro> |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="f2a6f4e8180cae2a-bee9da3c-453242b1-9af4b58b-30b50267b5249354da753b29"><ac:plain-text-body><![CDATA[ | [[J2SE 2011 | AA. Bibliography#J2SE 11]] | | ]]></ac:plain-text-body></ac:structured-macro> |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="04db69baf3f576d8-ee989188-4b4447dd-b287a4c4-77c96ba3913afca3210ff9a5"><ac:plain-text-body><![CDATA[ | [[Seacord 2005 | AA. Bibliography#Seacord 05]] | Chapter 7, "File I/O" | ]]></ac:plain-text-body></ac:structured-macro> |
...