pdfbox-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Glen Peterson (JIRA)" <j...@apache.org>
Subject [jira] [Updated] (PDFBOX-4242) Fontbox does not close file descriptor when loading fonts.
Date Thu, 07 Jun 2018 17:33:00 GMT

     [ https://issues.apache.org/jira/browse/PDFBOX-4242?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Glen Peterson updated PDFBOX-4242:
----------------------------------
    Description: 
My app has been getting "java.io.FileNotFoundException (No file descriptors available)" and
I think it's because fontbox isn't closing it's file descriptors.

In org.apache.fontbox.ttf.TTFParser there's this method:

{{public TrueTypeFont parse(File ttfFile) throws IOException {}}
 {{  RAFDataStream raf = new RAFDataStream(ttfFile, "r");try {}}
 {{    return this.parse((TTFDataStream)raf);}}
 {{  } catch (IOException var4) {}}
 {{    // close only on error (file is still being accessed later)}}
 {{    raf.close();}}
 {{    throw var4;}}
{{}}}

I would have expected to see the close() in a finally block so that the file is always closed,
not just on exceptions.  Presumably, you can keep it in memory without leaving the  file descriptor
open?

{{public TrueTypeFont parse(File ttfFile) throws IOException {}}
 {{  RAFDataStream raf = new RAFDataStream(ttfFile, "r");try {}}
 {{    return this.parse((TTFDataStream)raf);}}
 {{  } catch (IOException var4) {}}{{    raf.close();}}
 {{    throw var4;}}
 {{  } finally {}}
 {{    raf.close();}}
   {{}}}
 {{}}}

I can perform this in a lazy initialization, so if there's still good reason to leave the
file descriptor open, I can at least only leave it open once instead of every time someone
requests a PDF!

Thanks for PDFBox - it's been really helpful!

  was:
My app has been getting "java.io.FileNotFoundException (No file descriptors available)" and
I think it's because fontbox isn't closing it's file descriptors.

In org.apache.fontbox.ttf.TTFParser there's this method:

{{public TrueTypeFont parse(File ttfFile) throws IOException {}}
{{  RAFDataStream raf = new RAFDataStream(ttfFile, "r");try {}}
{{    return this.parse((TTFDataStream)raf);}}
{{  } catch (IOException var4) {}}{{    // close only on error (file is still being accessed
later)}}
{{    raf.close();}}
{{    throw var4;}}
{{  }}}
{{ }}}

I think 

{{public TrueTypeFont parse(File ttfFile) throws IOException {}}
{{  RAFDataStream raf = new RAFDataStream(ttfFile, "r");try {}}
{{    return this.parse((TTFDataStream)raf);}}
{{  } catch (IOException var4) {}}{{    raf.close();}}
{{    throw var4;}}
{{  } finally {}}{{    raf.close();}}{{     }}}
{{}}}

 


> Fontbox does not close file descriptor when loading fonts.
> ----------------------------------------------------------
>
>                 Key: PDFBOX-4242
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-4242
>             Project: PDFBox
>          Issue Type: Bug
>          Components: FontBox
>    Affects Versions: 2.0.9
>            Reporter: Glen Peterson
>            Priority: Minor
>
> My app has been getting "java.io.FileNotFoundException (No file descriptors available)"
and I think it's because fontbox isn't closing it's file descriptors.
> In org.apache.fontbox.ttf.TTFParser there's this method:
> {{public TrueTypeFont parse(File ttfFile) throws IOException {}}
>  {{  RAFDataStream raf = new RAFDataStream(ttfFile, "r");try {}}
>  {{    return this.parse((TTFDataStream)raf);}}
>  {{  } catch (IOException var4) {}}
>  {{    // close only on error (file is still being accessed later)}}
>  {{    raf.close();}}
>  {{    throw var4;}}
> {{}}}
> I would have expected to see the close() in a finally block so that the file is always
closed, not just on exceptions.  Presumably, you can keep it in memory without leaving the
 file descriptor open?
> {{public TrueTypeFont parse(File ttfFile) throws IOException {}}
>  {{  RAFDataStream raf = new RAFDataStream(ttfFile, "r");try {}}
>  {{    return this.parse((TTFDataStream)raf);}}
>  {{  } catch (IOException var4) {}}{{    raf.close();}}
>  {{    throw var4;}}
>  {{  } finally {}}
>  {{    raf.close();}}
>    {{}}}
>  {{}}}
> I can perform this in a lazy initialization, so if there's still good reason to leave
the file descriptor open, I can at least only leave it open once instead of every time someone
requests a PDF!
> Thanks for PDFBox - it's been really helpful!



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: dev-help@pdfbox.apache.org


Mime
View raw message