I have the following code in my app:
final File f = new File(path);
try {
boolean folderCreated = f.mkdirs();
// if dir wasn't created this time, and doesn't exist
if (!folderCreated && !f.exists()) {
throw new IOException("Unable to create path");
}
} catch (SecurityException e) {
throw new IOException("Unable to create path");
}
When I run findbugs (in Android Studio), it reports Bad Practice
Bad use of return value from method
Method ignores exceptional return value of java.io.File.mkdirs()
Javadoc states that java.io.File.mkdirs()
returns true if the directory was created, or false on failure OR if the directory already existed, hence the !f.exists()
check.
I don't want to ignore findbugs messages - not even warnings, but I don't see how I can resolve this as the return value is clearly being checked.
Note, I added the try{...}catch (SecurityException){...}
as a suggestion from this post: https://stackoverflow.com/a/23631948/1423896, but it doesn't make any difference.