Details
-
Bug
-
Status: Closed
-
Critical
-
Resolution: Auto Closed
-
None
-
None
-
None
Description
The fix revision 740164 was aimed to remove resource leak bugs on the FileWriter object "fileWriter"
(created in line 84) in the method "renderBook"of the file "/maven/doxia/doxia/trunk/doxia-
book/src/main/java/org/apache/maven/doxia/book/services/renderer/XHtmlBookRenderer.java" , but it is
incomplete.
There are some problems:
1. when the statements at lines 91 throw some exception, "fileWriter" will be leaked.
The best way to close such resource objects is putting such close operations for all resource
objects in the finaly block of a try-catch-finally structure and then putting all other code in a
try block.
The problem still exists in the head revision. The buggy code is copied as bellows:
public void renderBook( BookContext context )
throws BookDoxiaException
{
BookModel book = context.getBook();
if ( !context.getOutputDirectory().exists() )
{
if ( !context.getOutputDirectory().mkdirs() )
}
File bookFile = new File( context.getOutputDirectory(), book.getId() + ".xhtml" );
Writer fileWriter;
try
{ 84 fileWriter = new FileWriter( bookFile ); }catch ( IOException e )
{ throw new BookDoxiaException( "Error while opening file.", e ); }91 XhtmlBookSink sink = new XhtmlBookSink( fileWriter,
new RenderingContext( context.getOutputDirectory(), bookFile.getAbsolutePath() ) );
try
{ sink.bookHead(); ...... }finally
{ sink.flush(); sink.close(); IOUtil.close( fileWriter ); }}