Maven Doxia
  1. Maven Doxia
  2. DOXIA-461

An incomplete fix for the resource leak bugs in LatexBookRenderer.java

    Details

    • Type: Bug Bug
    • Status: Open Open
    • Priority: Critical Critical
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Module - Latex
    • Labels:
      None
    • Number of attachments :
      0

      Description

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

        Activity

        Hide
        Lukas Theussl added a comment -

        Please attach a patch instead of pasting code, see the Guide to Developing Maven.

        Show
        Lukas Theussl added a comment - Please attach a patch instead of pasting code, see the Guide to Developing Maven .

          People

          • Assignee:
            Unassigned
            Reporter:
            Guangtai Liang
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated: