[
https://jira.codehaus.org/browse/DOXIATOOLS-45?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Herve Boutemy moved DOXIA-461 to DOXIATOOLS-45:
-----------------------------------------------
Component/s: (was: Module - Latex)
Doxia Book Renderer
Key: DOXIATOOLS-45 (was: DOXIA-461)
Project: Maven Doxia Tools (was: Maven Doxia)
> An incomplete fix for the resource leak bugs in LatexBookRenderer.java
> ----------------------------------------------------------------------
>
> Key: DOXIATOOLS-45
> URL: https://jira.codehaus.org/browse/DOXIATOOLS-45
> Project: Maven Doxia Tools
> Issue Type: Bug
> Components: Doxia Book Renderer
> 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):
> {code}
> 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;
> }
> {code}
--
This message was sent by Atlassian JIRA
(v6.1.6#6162)