Uploaded image for project: 'Maven Doxia Tools'
  1. Maven Doxia Tools
  2. DOXIATOOLS-29

Another incomplete fix for the resource leak bugs in XHtmlBookRenderer.java

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Critical
    • Resolution: Auto Closed
    • None
    • None
    • Doxia Book Renderer
    • 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() )

      { 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 ); }

      }

      Attachments

        Activity

          People

            Unassigned Unassigned
            guangtai Guangtai Liang
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: