views:

167

answers:

1

I am encountering a strange issue with the commons-io/java-io. Essentially my file creation is failing silently without an exception.

FileUtils.writeLines(file, collectionOfStrings);

I've looked through the commons code to try and figure why this failing silently, but to me it looks like it should be throwing an exception. (See lines 1338, 163 in FileUtils.java and line 927 in IOUtils.java.)

In an effort to try to correct this issue, I added this check to the code after the previous line,

if (!file.exists()) {
    logger.warn("File creation failed.");
}

However, even when file creation fails, this block is not being entered.

I'm at my wits end with this one, can anyone with more experience with Java IO help me out?

A: 

I am a little embarrassed but I forgot to include the commons-io jar with my web application. Resulting in a run time issue.

My real issue was that the java.lang.NoClassDefFoundError: org/apache/commons/io/FileUtils message was not going into my log because NoClassDefFoundError is NOT an exception, wonderful architecture by Sun here.

When this NoClassDefFoundError was hit, the rest of the code didn't execute, including the file.exists() check.

James McMahon
Future note, if you want to catch any failures for your log, catch Throwable, not Exception.
james
@james, absolutely. I just switched all my top level logging catches to Throwable.
James McMahon