Bug 41790 - JDTCompiler::getContents does not close the reader
Summary: JDTCompiler::getContents does not close the reader
Status: RESOLVED FIXED
Alias: None
Product: Tomcat 5
Classification: Unclassified
Component: Jasper (show other bugs)
Version: Unknown
Hardware: Other Linux
: P2 normal (vote)
Target Milestone: ---
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-03-07 19:02 UTC by junwei.cheng
Modified: 2007-03-08 08:05 UTC (History)
1 user (show)



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description junwei.cheng 2007-03-07 19:02:57 UTC
In the class org.apache.jasper.compiler.JDTCompiler:
-------------------------------------------------------------------------
public char[] getContents() {
                char[] result = null;
                try {
                    InputStreamReader isReader =
                        new InputStreamReader(new FileInputStream(sourceFile),
                                ctxt.getOptions().getJavaEncoding());
                    Reader reader = new BufferedReader(isReader);
                    if (reader != null) {
                        char[] chars = new char[8192];
                        StringBuffer buf = new StringBuffer();
                        int count;
                        while ((count = reader.read(chars, 0, 
                                                    chars.length)) > 0) {
                            buf.append(chars, 0, count);
                        }
                        result = new char[buf.length()];
                        buf.getChars(0, result.length, result, 0);
                    }
                } catch (IOException e) {
                    log.error("Compilation error", e);
                }
                return result;
            }
-------------------------------------------------------------------------
the variable "reader" is not closed after use it. if I update jsp files 
frequently, it will exhaust the system file handler. "too many files" errors 
will come.

I test it on Redhat linux, the same problem will occured in tomcat 5 and tomcat 
6.
Comment 1 Sven 2007-03-07 19:39:51 UTC
Both the FileInputStream and the InputStreamReader should be closed within a
finally block.
Comment 2 Remy Maucherat 2007-03-08 08:05:04 UTC
Only the FileInputStream needs to be closed (the others are irrelevant).