An interesting situation. I have a section of code that creates several ZipOutputStreams. As a security check, before I even think about writing everything that I check, my output streams were correctly initialized:
ZipOutputStream countStream = null;
File countFile = null;
try {
countFile =
new File(savePath.getCanonicalPath() + savePath.separator + outputTag
+ "_COUNT_OUTPUTS.zip");
} catch (Exception e) {
outputLog.add("UNABLE TO FIND SAVE PATH");
return util.FILE_INVALID;
}
try {
if (countFile.exists() == true) {
countFile.delete();
} else {
}
countStream = new ZipOutputStream(new FileOutputStream(countFile));
} catch (Exception e) {
e.printStackTrace();
outputLog.add("UNABLE TO CREATE OUTPUT FILES");
return util.FILE_SAVE_FAIL;
}
if (countStream == null) {
outputLog.add("UNABLE TO CREATE OUTPUT FILES");
return util.FILE_SAVE_FAIL;
} else {
}
I don’t particularly see where the problem is in this code, but it triggers a warning about the null test: "Zero comparison always gives false: the countStream variable cannot be null in this place." As far as I can see this, I have a variable with initialization to zero, then an attempt is made to create an output stream, but it is not guaranteed. ignoring the warning is simple enough, but I'd better know how the compiler concludes that countStream is guaranteed to be successfully created.
K.Barad