[ https://issues.apache.org/jira/browse/GROOVY-8056?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15833694#comment-15833694 ]
John Wagenleitner commented on GROOVY-8056: ------------------------------------------- I think {{getContentEncoding()}} is not correct since we are looking for a charset but it returns how the content is compressed (i.e., gzip, deflate) that is specified in the [Content-Encoding HTTP Header|https://tools.ietf.org/html/rfc7231#section-3.1.2.2]. To obtain a charset it's the {{getContentType()}} value and it's in the form (when it's present) {{text/html; charset=UTF-8}}. Futher, I think we could skip this call completely if {{"file".equals(url.getProtocol())}} since no Content-Type header will be available. > GroovyCodeSource(URL) can leak a file handler > --------------------------------------------- > > Key: GROOVY-8056 > URL: https://issues.apache.org/jira/browse/GROOVY-8056 > Project: Groovy > Issue Type: Bug > Affects Versions: 2.4.8 > Reporter: Andy Wilkinson > > 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: > {noformat} > 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) > {noformat} > I believe that keeping a local reference to the {{URLConnection}} and then > calling {{getInputStream().close()}} on it will fix the problem. > For reference > [this|https://github.com/spring-projects/spring-boot/issues/7892] is the > Spring Boot issues where the problem was originally reported. -- This message was sent by Atlassian JIRA (v6.3.4#6332)