You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by "Guangtai Liang (JIRA)" <ji...@codehaus.org> on 2012/02/22 13:42:02 UTC
[jira] (DOXIA-461) An incomplete fix for the resource leak bugs in
LatexBookRenderer.java
Guangtai Liang created DOXIA-461:
------------------------------------
Summary: An incomplete fix for the resource leak bugs in LatexBookRenderer.java
Key: DOXIA-461
URL: https://jira.codehaus.org/browse/DOXIA-461
Project: Maven Doxia
Issue Type: Bug
Components: Module - Latex
Reporter: Guangtai Liang
Priority: Critical
The fix revision 740164 was aimed to remove resource leak bugs on the FileWriter object "writer"(created in line 204) and the FileReader object "reader" (created in line 219) in the method "writeSection()"of the file " /maven/doxia/doxia/trunk/doxia-book/src/main/java/org/apache/maven/doxia/book/services/renderer/LatexBookRenderer.java" , but it is incomplete.
There are some problems:
1. the LatexBookSink object "sink" is not closed.
2. when the statements at lines 206-215 throw some exception, "writer" 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.
Although a later fix (rev1003021) try to close "sink", the problems still exists in the head revision. The buggy code is copied as bellows ("sink" and "writer" will be leaked when the statements at lines 202-207 throw some exception):
private SectionInfo writeSection( Section section, BookContext context )
throws IOException, BookDoxiaException
{
File file = new File( context.getOutputDirectory(), ( section.getId() + ".tex" ) );
198 Writer writer = WriterFactory.newWriter( file, context.getOutputEncoding() );
200 LatexBookSink sink = new LatexBookSink( writer );
BookContext.BookFile bookFile = (BookContext.BookFile) context.getFiles().get( section.getId() );
if ( bookFile == null )
{
throw new BookDoxiaException( "No document that matches section with id="
+ section.getId() + "." );
}
Reader reader = null;
try
{
reader = ReaderFactory.newReader( bookFile.getFile(), context.getInputEncoding() );
doxia.parse( reader, bookFile.getParserId(), sink );
}
catch ( ParserNotFoundException e )
{
throw new BookDoxiaException( "Parser not found: "
+ bookFile.getParserId() + ".", e );
}
catch ( ParseException e )
{
throw new BookDoxiaException( "Error while parsing document: "
+ bookFile.getFile().getAbsolutePath() + ".", e );
}
catch ( FileNotFoundException e )
{
throw new BookDoxiaException( "Could not find document: "
+ bookFile.getFile().getAbsolutePath() + ".", e );
}
finally
{
233 sink.flush();
234 sink.close();
236 IOUtil.close( reader );
237 IOUtil.close( writer );
}
SectionInfo info = new SectionInfo();
info.id = section.getId();
info.title = sink.getTitle();
return info;
}
--
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
[jira] (DOXIA-461) An incomplete fix for the resource leak bugs in
LatexBookRenderer.java
Posted by "Lukas Theussl (JIRA)" <ji...@codehaus.org>.
[ https://jira.codehaus.org/browse/DOXIA-461?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=292440#comment-292440 ]
Lukas Theussl commented on DOXIA-461:
-------------------------------------
Please attach a patch instead of pasting code, see the [Guide to Developing Maven|http://maven.apache.org/guides/development/guide-m2-development.html#Creating_and_submitting_a_patch].
> An incomplete fix for the resource leak bugs in LatexBookRenderer.java
> ----------------------------------------------------------------------
>
> Key: DOXIA-461
> URL: https://jira.codehaus.org/browse/DOXIA-461
> Project: Maven Doxia
> Issue Type: Bug
> Components: Module - Latex
> Reporter: Guangtai Liang
> Priority: Critical
>
> The fix revision 740164 was aimed to remove resource leak bugs on the FileWriter object "writer"(created in line 204) and the FileReader object "reader" (created in line 219) in the method "writeSection()"of the file " /maven/doxia/doxia/trunk/doxia-book/src/main/java/org/apache/maven/doxia/book/services/renderer/LatexBookRenderer.java" , but it is incomplete.
> There are some problems:
> 1. the LatexBookSink object "sink" is not closed.
> 2. when the statements at lines 206-215 throw some exception, "writer" 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.
> Although a later fix (rev1003021) try to close "sink", the problems still exists in the head revision. The buggy code is copied as bellows ("sink" and "writer" will be leaked when the statements at lines 202-207 throw some exception):
> private SectionInfo writeSection( Section section, BookContext context )
> throws IOException, BookDoxiaException
> {
> File file = new File( context.getOutputDirectory(), ( section.getId() + ".tex" ) );
> 198 Writer writer = WriterFactory.newWriter( file, context.getOutputEncoding() );
> 200 LatexBookSink sink = new LatexBookSink( writer );
> BookContext.BookFile bookFile = (BookContext.BookFile) context.getFiles().get( section.getId() );
> if ( bookFile == null )
> {
> throw new BookDoxiaException( "No document that matches section with id="
> + section.getId() + "." );
> }
> Reader reader = null;
> try
> {
> reader = ReaderFactory.newReader( bookFile.getFile(), context.getInputEncoding() );
> doxia.parse( reader, bookFile.getParserId(), sink );
> }
> catch ( ParserNotFoundException e )
> {
> throw new BookDoxiaException( "Parser not found: "
> + bookFile.getParserId() + ".", e );
> }
> catch ( ParseException e )
> {
> throw new BookDoxiaException( "Error while parsing document: "
> + bookFile.getFile().getAbsolutePath() + ".", e );
> }
> catch ( FileNotFoundException e )
> {
> throw new BookDoxiaException( "Could not find document: "
> + bookFile.getFile().getAbsolutePath() + ".", e );
> }
> finally
> {
> 233 sink.flush();
> 234 sink.close();
> 236 IOUtil.close( reader );
> 237 IOUtil.close( writer );
> }
> SectionInfo info = new SectionInfo();
> info.id = section.getId();
> info.title = sink.getTitle();
> return info;
> }
--
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