Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Java's file-manipulation functions often indicate failure with a return value , rather than throwing an exception. The Java Tutorial for Java 7 notes:

...

Consequently, file operations can silently fail if the methods' return values are ignored. Java programs must check the return values of method methods that perform file I/O (this is a specific instance of rule EXP00-J. Do not ignore values returned by methods).)

Noncompliant Code Example (delete())

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}} if the program is not authorized to delete the file. No other exceptions are thrown
;
, so the deletion can silently fail.

Code Block
bgColor#FFCCCC
File file = /* initialize */
file.delete();

...

Bibliography

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="01ffd590-d0e5-4ba7-a61b-92d48b428366"><ac:plain-text-body><![CDATA[

[[API 2006

AA. Bibliography#API 06]]

File.delete()

]]></ac:plain-text-body></ac:structured-macro>

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="33fb147cec43ec0b-d0d60b38-4d9c4a06-8b14a562-f773246519f5361b06162938"><ac:plain-text-body><![CDATA[

[[J2SE 2011

AA. Bibliography#J2SE 11]]

Files.delete()

]]></ac:plain-text-body></ac:structured-macro>

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="3e2020ee1b964333-3e240872-467c462d-a632b4e2-fffe66bf6197dd2e053b8daa"><ac:plain-text-body><![CDATA[

[[Seacord 2005a

AA. Bibliography#Seacord 05]]

Chapter 7, "File I/O"

]]></ac:plain-text-body></ac:structured-macro>

...