You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by vi...@apache.org on 2014/09/03 20:22:14 UTC
svn commit: r1622312 - in /tomcat/trunk:
java/org/apache/catalina/util/CharsetMapper.java
java/org/apache/tomcat/util/descriptor/web/FragmentJarScannerCallback.java
webapps/docs/changelog.xml
Author: violetagg
Date: Wed Sep 3 18:22:14 2014
New Revision: 1622312
URL: http://svn.apache.org/r1622312
Log:
Fix some potential resource leaks when reading files and other resources. Reported by Coverity Scan.
Modified:
tomcat/trunk/java/org/apache/catalina/util/CharsetMapper.java
tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/FragmentJarScannerCallback.java
tomcat/trunk/webapps/docs/changelog.xml
Modified: tomcat/trunk/java/org/apache/catalina/util/CharsetMapper.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/util/CharsetMapper.java?rev=1622312&r1=1622311&r2=1622312&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/util/CharsetMapper.java (original)
+++ tomcat/trunk/java/org/apache/catalina/util/CharsetMapper.java Wed Sep 3 18:22:14 2014
@@ -69,11 +69,8 @@ public class CharsetMapper {
* resource could not be loaded for any reason.
*/
public CharsetMapper(String name) {
- try {
- InputStream stream =
- this.getClass().getResourceAsStream(name);
+ try (InputStream stream = this.getClass().getResourceAsStream(name)) {
map.load(stream);
- stream.close();
} catch (Throwable t) {
ExceptionUtils.handleThrowable(t);
throw new IllegalArgumentException(t.toString());
Modified: tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/FragmentJarScannerCallback.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/FragmentJarScannerCallback.java?rev=1622312&r1=1622311&r2=1622312&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/FragmentJarScannerCallback.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/FragmentJarScannerCallback.java Wed Sep 3 18:22:14 2014
@@ -111,15 +111,13 @@ public class FragmentJarScannerCallback
@Override
public void scan(File file, String webappPath, boolean isWebapp) throws IOException {
- InputStream stream = null;
WebXml fragment = new WebXml();
fragment.setWebappJar(isWebapp);
fragment.setDelegate(delegate);
- try {
- File fragmentFile = new File(file, FRAGMENT_LOCATION);
+ File fragmentFile = new File(file, FRAGMENT_LOCATION);
+ try (InputStream stream = new FileInputStream(fragmentFile)) {
if (fragmentFile.isFile()) {
- stream = new FileInputStream(fragmentFile);
InputSource source =
new InputSource(fragmentFile.toURI().toURL().toString());
source.setByteStream(stream);
Modified: tomcat/trunk/webapps/docs/changelog.xml
URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1622312&r1=1622311&r2=1622312&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/trunk/webapps/docs/changelog.xml Wed Sep 3 18:22:14 2014
@@ -99,8 +99,8 @@
extension dependencies reported by Coverity Scan. (violetagg)
</fix>
<fix>
- Fix some potential resource leaks when reading property files. Reported
- by Coverity Scan. (violetagg)
+ Fix some potential resource leaks when reading properties, files and
+ other resources. Reported by Coverity Scan. (violetagg)
</fix>
</changelog>
</subsection>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org
Re: svn commit: r1622312 - in /tomcat/trunk: java/org/apache/catalina/util/CharsetMapper.java
java/org/apache/tomcat/util/descriptor/web/FragmentJarScannerCallback.java
webapps/docs/changelog.xml
Posted by Mark Thomas <ma...@apache.org>.
On 05/09/2014 15:51, Violeta Georgieva wrote:
> Hi Mark,
>
> 2014-09-05 16:57 GMT+03:00 Mark Thomas <ma...@apache.org>:
>>
>> On 03/09/2014 19:22, violetagg@apache.org wrote:
>>> Author: violetagg
>>> Date: Wed Sep 3 18:22:14 2014
>>> New Revision: 1622312
>>>
>>> URL: http://svn.apache.org/r1622312
>>> Log:
>>> Fix some potential resource leaks when reading files and other
> resources. Reported by Coverity Scan.
>>>
>>> Modified:
>>> tomcat/trunk/java/org/apache/catalina/util/CharsetMapper.java
>>>
> tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/FragmentJarScannerCallback.java
>>
>> I'm guessing you haven't started a Tomcat instance built after this
>> change was made. Lots of FNFE appear in the logs.
>>
>> <snip/>
>>
>>> Modified:
> tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/FragmentJarScannerCallback.java
>>> URL:
> http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/FragmentJarScannerCallback.java?rev=1622312&r1=1622311&r2=1622312&view=diff
>>>
> ==============================================================================
>>> ---
> tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/FragmentJarScannerCallback.java
> (original)
>>> +++
> tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/FragmentJarScannerCallback.java
> Wed Sep 3 18:22:14 2014
>>> @@ -111,15 +111,13 @@ public class FragmentJarScannerCallback
>>> @Override
>>> public void scan(File file, String webappPath, boolean isWebapp)
> throws IOException {
>>>
>>> - InputStream stream = null;
>>> WebXml fragment = new WebXml();
>>> fragment.setWebappJar(isWebapp);
>>> fragment.setDelegate(delegate);
>>>
>>> - try {
>>> - File fragmentFile = new File(file, FRAGMENT_LOCATION);
>>> + File fragmentFile = new File(file, FRAGMENT_LOCATION);
>>> + try (InputStream stream = new FileInputStream(fragmentFile)) {
>>> if (fragmentFile.isFile()) {
>>> - stream = new FileInputStream(fragmentFile);
>>> InputSource source =
>>> new
> InputSource(fragmentFile.toURI().toURL().toString());
>>> source.setByteStream(stream);
>>
>> Here is the problem. You moved the creation of the stream to before the
>> isFile() test.
>>
>> Should be an easy fix.
>
> Thanks for the fix that you provided. I was not available today :(
> Please accept my apologies. I'll be more care in the future with the "easy"
> fixes.
I wouldn't worry about. It happens to all of us. Well, it happens a lot
to me anyway.
Mark
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org
Re: svn commit: r1622312 - in /tomcat/trunk: java/org/apache/catalina/util/CharsetMapper.java
java/org/apache/tomcat/util/descriptor/web/FragmentJarScannerCallback.java webapps/docs/changelog.xml
Posted by Violeta Georgieva <mi...@gmail.com>.
Hi Mark,
2014-09-05 16:57 GMT+03:00 Mark Thomas <ma...@apache.org>:
>
> On 03/09/2014 19:22, violetagg@apache.org wrote:
> > Author: violetagg
> > Date: Wed Sep 3 18:22:14 2014
> > New Revision: 1622312
> >
> > URL: http://svn.apache.org/r1622312
> > Log:
> > Fix some potential resource leaks when reading files and other
resources. Reported by Coverity Scan.
> >
> > Modified:
> > tomcat/trunk/java/org/apache/catalina/util/CharsetMapper.java
> >
tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/FragmentJarScannerCallback.java
>
> I'm guessing you haven't started a Tomcat instance built after this
> change was made. Lots of FNFE appear in the logs.
>
> <snip/>
>
> > Modified:
tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/FragmentJarScannerCallback.java
> > URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/FragmentJarScannerCallback.java?rev=1622312&r1=1622311&r2=1622312&view=diff
> >
==============================================================================
> > ---
tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/FragmentJarScannerCallback.java
(original)
> > +++
tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/FragmentJarScannerCallback.java
Wed Sep 3 18:22:14 2014
> > @@ -111,15 +111,13 @@ public class FragmentJarScannerCallback
> > @Override
> > public void scan(File file, String webappPath, boolean isWebapp)
throws IOException {
> >
> > - InputStream stream = null;
> > WebXml fragment = new WebXml();
> > fragment.setWebappJar(isWebapp);
> > fragment.setDelegate(delegate);
> >
> > - try {
> > - File fragmentFile = new File(file, FRAGMENT_LOCATION);
> > + File fragmentFile = new File(file, FRAGMENT_LOCATION);
> > + try (InputStream stream = new FileInputStream(fragmentFile)) {
> > if (fragmentFile.isFile()) {
> > - stream = new FileInputStream(fragmentFile);
> > InputSource source =
> > new
InputSource(fragmentFile.toURI().toURL().toString());
> > source.setByteStream(stream);
>
> Here is the problem. You moved the creation of the stream to before the
> isFile() test.
>
> Should be an easy fix.
Thanks for the fix that you provided. I was not available today :(
Please accept my apologies. I'll be more care in the future with the "easy"
fixes.
Regards,
Violeta
> Mark
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: dev-help@tomcat.apache.org
>
Re: svn commit: r1622312 - in /tomcat/trunk: java/org/apache/catalina/util/CharsetMapper.java
java/org/apache/tomcat/util/descriptor/web/FragmentJarScannerCallback.java
webapps/docs/changelog.xml
Posted by Mark Thomas <ma...@apache.org>.
On 03/09/2014 19:22, violetagg@apache.org wrote:
> Author: violetagg
> Date: Wed Sep 3 18:22:14 2014
> New Revision: 1622312
>
> URL: http://svn.apache.org/r1622312
> Log:
> Fix some potential resource leaks when reading files and other resources. Reported by Coverity Scan.
>
> Modified:
> tomcat/trunk/java/org/apache/catalina/util/CharsetMapper.java
> tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/FragmentJarScannerCallback.java
I'm guessing you haven't started a Tomcat instance built after this
change was made. Lots of FNFE appear in the logs.
<snip/>
> Modified: tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/FragmentJarScannerCallback.java
> URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/FragmentJarScannerCallback.java?rev=1622312&r1=1622311&r2=1622312&view=diff
> ==============================================================================
> --- tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/FragmentJarScannerCallback.java (original)
> +++ tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/FragmentJarScannerCallback.java Wed Sep 3 18:22:14 2014
> @@ -111,15 +111,13 @@ public class FragmentJarScannerCallback
> @Override
> public void scan(File file, String webappPath, boolean isWebapp) throws IOException {
>
> - InputStream stream = null;
> WebXml fragment = new WebXml();
> fragment.setWebappJar(isWebapp);
> fragment.setDelegate(delegate);
>
> - try {
> - File fragmentFile = new File(file, FRAGMENT_LOCATION);
> + File fragmentFile = new File(file, FRAGMENT_LOCATION);
> + try (InputStream stream = new FileInputStream(fragmentFile)) {
> if (fragmentFile.isFile()) {
> - stream = new FileInputStream(fragmentFile);
> InputSource source =
> new InputSource(fragmentFile.toURI().toURL().toString());
> source.setByteStream(stream);
Here is the problem. You moved the creation of the stream to before the
isFile() test.
Should be an easy fix.
Mark
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org