You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by pe...@apache.org on 2007/02/07 10:25:53 UTC
svn commit: r504474 -
/tomcat/jasper/tc5.5.x/src/share/org/apache/jasper/compiler/JDTCompiler.java
Author: pero
Date: Wed Feb 7 01:25:52 2007
New Revision: 504474
URL: http://svn.apache.org/viewvc?view=rev&rev=504474
Log:
Fix Bug 41554: The input stream of the JSP file for compiling is not closed.
OK, find another not right IOE Handling and fix it.
Modified:
tomcat/jasper/tc5.5.x/src/share/org/apache/jasper/compiler/JDTCompiler.java
Modified: tomcat/jasper/tc5.5.x/src/share/org/apache/jasper/compiler/JDTCompiler.java
URL: http://svn.apache.org/viewvc/tomcat/jasper/tc5.5.x/src/share/org/apache/jasper/compiler/JDTCompiler.java?view=diff&rev=504474&r1=504473&r2=504474
==============================================================================
--- tomcat/jasper/tc5.5.x/src/share/org/apache/jasper/compiler/JDTCompiler.java (original)
+++ tomcat/jasper/tc5.5.x/src/share/org/apache/jasper/compiler/JDTCompiler.java Wed Feb 7 01:25:52 2007
@@ -99,11 +99,13 @@
public char[] getContents() {
char[] result = null;
+ Reader reader = null ;
+ InputStreamReader isReader = null ;
try {
- InputStreamReader isReader =
+ isReader =
new InputStreamReader(new FileInputStream(sourceFile),
ctxt.getOptions().getJavaEncoding());
- Reader reader = new BufferedReader(isReader);
+ reader = new BufferedReader(isReader);
if (reader != null) {
char[] chars = new char[8192];
StringBuffer buf = new StringBuffer();
@@ -117,6 +119,13 @@
}
} catch (IOException e) {
log.error("Compilation error", e);
+ } finally {
+ if(isReader != null)
+ try { isReader.close() ; }
+ catch (IOException ignore) {}
+ if(reader != null)
+ try { reader.close() ; }
+ catch (IOException ignore) {}
}
return result;
}
@@ -340,55 +349,66 @@
new DefaultProblemFactory(Locale.getDefault());
final ICompilerRequestor requestor = new ICompilerRequestor() {
- public void acceptResult(CompilationResult result) {
- try {
- if (result.hasProblems()) {
- IProblem[] problems = result.getProblems();
- for (int i = 0; i < problems.length; i++) {
- IProblem problem = problems[i];
- if (problem.isError()) {
- String name =
- new String(problems[i].getOriginatingFileName());
- try {
- problemList.add(ErrorDispatcher.createJavacError
- (name, pageNodes, new StringBuffer(problem.getMessage()),
- problem.getSourceLineNumber(),ctxt));
- } catch (JasperException e) {
- log.error("Error visiting node", e);
- }
- }
+ public void acceptResult(CompilationResult result) {
+ if (result.hasProblems()) {
+ IProblem[] problems = result.getProblems();
+ for (int i = 0; i < problems.length; i++) {
+ IProblem problem = problems[i];
+ if (problem.isError()) {
+ String name = new String(problems[i]
+ .getOriginatingFileName());
+ try {
+ problemList.add(ErrorDispatcher
+ .createJavacError(name, pageNodes,
+ new StringBuffer(problem
+ .getMessage()), problem
+ .getSourceLineNumber(),
+ ctxt));
+ } catch (JasperException e) {
+ log.error("Error visiting node", e);
}
}
- if (problemList.isEmpty()) {
- ClassFile[] classFiles = result.getClassFiles();
- for (int i = 0; i < classFiles.length; i++) {
- ClassFile classFile = classFiles[i];
- char[][] compoundName =
- classFile.getCompoundName();
- String className = "";
- String sep = "";
- for (int j = 0;
- j < compoundName.length; j++) {
- className += sep;
- className += new String(compoundName[j]);
- sep = ".";
+ }
+ }
+ if (problemList.isEmpty()) {
+ ClassFile[] classFiles = result.getClassFiles();
+ for (int i = 0; i < classFiles.length; i++) {
+ ClassFile classFile = classFiles[i];
+ char[][] compoundName = classFile.getCompoundName();
+ String className = "";
+ String sep = "";
+ for (int j = 0; j < compoundName.length; j++) {
+ className += sep;
+ className += new String(compoundName[j]);
+ sep = ".";
+ }
+ byte[] bytes = classFile.getBytes();
+ String outFile = outputDir + "/"
+ + className.replace('.', '/') + ".class";
+ FileOutputStream fout = null;
+ BufferedOutputStream bos = null;
+ try {
+ fout = new FileOutputStream(outFile);
+ bos = new BufferedOutputStream(fout);
+ bos.write(bytes);
+ } catch (IOException ioe) {
+ log.error("Compilation error", ioe);
+ } finally {
+ if (fout != null)
+ try {
+ fout.close();
+ } catch (IOException ignore) {
+ }
+ if (bos != null)
+ try {
+ bos.close();
+ } catch (IOException ignore) {
}
- byte[] bytes = classFile.getBytes();
- String outFile = outputDir + "/" +
- className.replace('.', '/') + ".class";
- FileOutputStream fout =
- new FileOutputStream(outFile);
- BufferedOutputStream bos =
- new BufferedOutputStream(fout);
- bos.write(bytes);
- bos.close();
- }
}
- } catch (IOException exc) {
- log.error("Compilation error", exc);
}
}
- };
+ }
+ };
ICompilationUnit[] compilationUnits =
new ICompilationUnit[classNames.length];
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org