Bug 61364

Summary: Stream not closed when detecting encoding of a JSP
Product: Tomcat 8 Reporter: Peter Stöckli <peter.stockli>
Component: JasperAssignee: Tomcat Developers Mailing List <dev>
Severity: normal    
Priority: P2    
Version: 8.5.16   
Target Milestone: ----   
Hardware: PC   
OS: All   

Description Peter Stöckli 2017-07-31 10:07:00 UTC
We had an issue that prevented us from deleting certain JSPs in an embedded Tomcat.
The cause of that seems to be that an InputStream is not closed after trying to figure out the encoding of a .jsp file.

From our point of view this seems to affect at least Tomcat 8.5.16 with following classes involved:

> 321: InputStream inStream = JspUtil.getInputStream(absFileName, jar, ctxt);
> 322: EncodingDetector encodingDetector = new EncodingDetector(inStream);
=> The InputStream is retrieved and passed to the EncodingDetector.

> 96:  XMLStreamReader xmlStreamReader = XML_INPUT_FACTORY.createXMLStreamReader(stream);
=> The EncodingDetector creates an XMLStreamReader on its static XML_INPUT_FACTORY.

As a workaround we configured the JspConfig like this to prevent the detection of the encoding:

> <jsp-config>
>   <jsp-property-group>
>     <url-pattern>*.jsp</url-pattern>
>     <is-xml>false</is-xml>
>   </jsp-property-group>
> </jsp-config>
Comment 1 Mark Thomas 2017-08-01 12:12:22 UTC
For anyone trying to reproduce this, you'll need to disable resource caching for the associated Context.

It is also a lot easier to reproduce on Windows since Windows prevents deletion of locked files.

This has been fixed in :
- trunk for 9.0.0.M26 onwards
- 8.5.x for 8.5.20 onwards

Many thanks for the report and the analysis to pin-point the issue.