Details
Description
o.a.avro.file.DataFileWriter implements java.io.Closeable, but violates the contract stated by the interface's close() method javadoc.
Closes this stream and releases any system resources associated
with it. If the stream is already closed then invoking this
method has no effect.
DataFileWriter's close() calls flush() calls sync() which calls assertOpen(). This causes repeated calls to close(), or those on a file that failed to open, to throw an exception which violates the contract. Notably, the following idiom fails (and shouldn't).
import com.google.common.io.Closeables; // ... DataFileWriter writer = null; try { writer = new DataFileWriter(...); // ... } finally { Closeables.closeQuietly(writer); }