Guangtai Liang created DOXIA-462:
------------------------------------
Summary: Another incomplete fix for the resource leak bugs in
XHtmlBookRenderer.java
Key: DOXIA-462
URL: https://jira.codehaus.org/browse/DOXIA-462
Project: Maven Doxia
Issue Type: Bug
Reporter: Guangtai Liang
Priority: Critical
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() )
{
throw new BookDoxiaException( "Could not make directory: "
+ context.getOutputDirectory().getAbsolutePath() +
"." );
}
}
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 );
}
}
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators:
https://jira.codehaus.org/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira