Bug 61364 - Stream not closed when detecting encoding of a JSP
Summary: Stream not closed when detecting encoding of a JSP
Status: RESOLVED FIXED
Alias: None
Product: Tomcat 8
Classification: Unclassified
Component: Jasper (show other bugs)
Version: 8.5.16
Hardware: PC All
: P2 normal (vote)
Target Milestone: ----
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-07-31 10:07 UTC by Peter Stöckli
Modified: 2017-08-01 12:12 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
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:

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


org.apache.jasper.compiler.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.