Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-8056

GroovyCodeSource(URL) can leak a file handler

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.4.8
    • 2.4.12
    • None
    • None

    Description

      When GroovyCodeSource is created from a URL it calls url.openConnection.getContentEncoding(). When it's a file: URL, this causes a FileInputStream to be opened and never closed. The stack trace for it being opened is:

      at java.io.FileInputStream.<init>(Unknown Source)
      	at java.io.FileInputStream.<init>(Unknown Source)
      	at sun.net.www.protocol.file.FileURLConnection.connect(Unknown Source)
      	at sun.net.www.protocol.file.FileURLConnection.initializeHeaders(Unknown Source)
      	at sun.net.www.protocol.file.FileURLConnection.getHeaderField(Unknown Source)
      	at java.net.URLConnection.getContentEncoding(Unknown Source)
      	at groovy.lang.GroovyCodeSource.<init>(GroovyCodeSource.java:176)
      	at groovy.text.markup.MarkupTemplateEngine$MarkupTemplateMaker.<init>(MarkupTemplateEngine.java:222)
      	at groovy.text.markup.MarkupTemplateEngine.createTemplateByPath(MarkupTemplateEngine.java:145)
      

      I believe that keeping a local reference to the URLConnection and then calling getInputStream().close() on it will fix the problem.

      For reference this is the Spring Boot issues where the problem was originally reported.

      Attachments

        Activity

          People

            jwagenleitner John Wagenleitner
            awilkinson Andy Wilkinson
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: