From: markt Date: Tue, 7 Dec 2010 18:36:39 +0000 (+0000) Subject: Fix some FindBugs warnings - all unclosed streams. These could potentially lead to... X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=2d95d4896b25cd1c6c045dd4012e02cd5c93236b;p=tomcat7.0 Fix some FindBugs warnings - all unclosed streams. These could potentially lead to locked files and maybe memory leaks. Fix some other simple FindBugs/Eclipse warnings in affected files. git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1043157 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/java/javax/el/ExpressionFactory.java b/java/javax/el/ExpressionFactory.java index 6f441367c..7f4a2401e 100644 --- a/java/javax/el/ExpressionFactory.java +++ b/java/javax/el/ExpressionFactory.java @@ -219,9 +219,9 @@ public abstract class ExpressionFactory { if (is != null) { String line = null; + BufferedReader br = null; try { - BufferedReader br = - new BufferedReader(new InputStreamReader(is, "UTF-8")); + br = new BufferedReader(new InputStreamReader(is, "UTF-8")); line = br.readLine(); if (line != null && line.trim().length() > 0) { return line.trim(); @@ -234,10 +234,13 @@ public abstract class ExpressionFactory { e); } finally { try { + if (br != null) { + br.close(); + } + } catch (IOException ioe) {/*Ignore*/} + try { is.close(); - } catch (IOException ioe) { - // Ignore - } + } catch (IOException ioe) {/*Ignore*/} } } diff --git a/java/org/apache/catalina/core/StandardContext.java b/java/org/apache/catalina/core/StandardContext.java index d6be6309f..a6245463d 100644 --- a/java/org/apache/catalina/core/StandardContext.java +++ b/java/org/apache/catalina/core/StandardContext.java @@ -5897,21 +5897,26 @@ public class StandardContext extends ContainerBase if (stream == null) { return ""; } - BufferedReader br = new BufferedReader( - new InputStreamReader(stream)); StringBuilder sb = new StringBuilder(); - String strRead = ""; + BufferedReader br = null; try { + br = new BufferedReader(new InputStreamReader(stream)); + String strRead = ""; while (strRead != null) { sb.append(strRead); strRead = br.readLine(); } } catch (IOException e) { return ""; + } finally { + if (br != null) { + try { + br.close(); + } catch (IOException ioe) {/*Ignore*/} + } } return sb.toString(); - } diff --git a/java/org/apache/jasper/compiler/JDTCompiler.java b/java/org/apache/jasper/compiler/JDTCompiler.java index 5af0d3f1c..3435bc2be 100644 --- a/java/org/apache/jasper/compiler/JDTCompiler.java +++ b/java/org/apache/jasper/compiler/JDTCompiler.java @@ -98,17 +98,21 @@ public class JDTCompiler extends org.apache.jasper.compiler.Compiler { this.sourceFile = sourceFile; } + @Override public char[] getFileName() { return sourceFile.toCharArray(); } + @Override public char[] getContents() { char[] result = null; FileInputStream is = null; + Reader reader = null; try { is = new FileInputStream(sourceFile); - Reader reader = - new BufferedReader(new InputStreamReader(is, ctxt.getOptions().getJavaEncoding())); + + reader = new BufferedReader(new InputStreamReader(is, + ctxt.getOptions().getJavaEncoding())); char[] chars = new char[8192]; StringBuilder buf = new StringBuilder(); int count; @@ -121,17 +125,21 @@ public class JDTCompiler extends org.apache.jasper.compiler.Compiler { } catch (IOException e) { log.error("Compilation error", e); } finally { + if (reader != null) { + try { + reader.close(); + } catch (IOException ioe) {/*Ignore*/} + } if (is != null) { try { is.close(); - } catch (IOException exc) { - // Ignore - } + } catch (IOException exc) {/*Ignore*/} } } return result; } + @Override public char[] getMainTypeName() { int dot = className.lastIndexOf('.'); if (dot > 0) { @@ -140,6 +148,7 @@ public class JDTCompiler extends org.apache.jasper.compiler.Compiler { return className.toCharArray(); } + @Override public char[][] getPackageName() { StringTokenizer izer = new StringTokenizer(className, "."); @@ -154,6 +163,7 @@ public class JDTCompiler extends org.apache.jasper.compiler.Compiler { final INameEnvironment env = new INameEnvironment() { + @Override public NameEnvironmentAnswer findType(char[][] compoundTypeName) { String result = ""; @@ -166,6 +176,7 @@ public class JDTCompiler extends org.apache.jasper.compiler.Compiler { return findType(result); } + @Override public NameEnvironmentAnswer findType(char[] typeName, char[][] packageName) { @@ -238,6 +249,7 @@ public class JDTCompiler extends org.apache.jasper.compiler.Compiler { return is == null; } + @Override public boolean isPackage(char[][] parentPackageName, char[] packageName) { String result = ""; @@ -261,6 +273,7 @@ public class JDTCompiler extends org.apache.jasper.compiler.Compiler { return isPackage(result); } + @Override public void cleanup() { } @@ -367,6 +380,7 @@ public class JDTCompiler extends org.apache.jasper.compiler.Compiler { new DefaultProblemFactory(Locale.getDefault()); final ICompilerRequestor requestor = new ICompilerRequestor() { + @Override public void acceptResult(CompilationResult result) { try { if (result.hasProblems()) { diff --git a/java/org/apache/tomcat/util/net/NioEndpoint.java b/java/org/apache/tomcat/util/net/NioEndpoint.java index 5c9a3a769..2df3759a8 100644 --- a/java/org/apache/tomcat/util/net/NioEndpoint.java +++ b/java/org/apache/tomcat/util/net/NioEndpoint.java @@ -492,13 +492,33 @@ public class NioEndpoint extends AbstractEndpoint { String ttype = (getTruststoreType()!=null)?getTruststoreType():getKeystoreType(); KeyStore ks = KeyStore.getInstance(getKeystoreType()); - ks.load(new FileInputStream(getKeystoreFile()), passphrase); + FileInputStream fisKeyStore = null; + try { + fisKeyStore = new FileInputStream(getKeystoreFile()); + ks.load(fisKeyStore, passphrase); + } finally { + if (fisKeyStore != null) { + try { + fisKeyStore.close(); + } catch (IOException ioe) {/*Ignore*/} + } + } KeyStore ts = null; if (getTruststoreFile()==null) { //no op, same as for BIO connector }else { ts = KeyStore.getInstance(ttype); - ts.load(new FileInputStream(getTruststoreFile()), tpassphrase); + FileInputStream fisTrustStore = null; + try { + fisTrustStore = new FileInputStream(getTruststoreFile()); + ts.load(fisTrustStore, tpassphrase); + } finally { + if (fisTrustStore != null) { + try { + fisTrustStore.close(); + } catch (IOException ioe) {/*Ignore*/} + } + } } KeyManagerFactory kmf = KeyManagerFactory.getInstance(getAlgorithm()); @@ -855,7 +875,7 @@ public class NioEndpoint extends AbstractEndpoint { * * PollerEvent, cacheable object for poller events to avoid GC */ - public class PollerEvent implements Runnable { + public static class PollerEvent implements Runnable { protected NioChannel socket; protected int interestOps; @@ -1444,7 +1464,7 @@ public class NioEndpoint extends AbstractEndpoint { } // ------------------------------------------------ Application Buffer Handler - public class NioBufferHandler implements ApplicationBufferHandler { + public static class NioBufferHandler implements ApplicationBufferHandler { protected ByteBuffer readbuf = null; protected ByteBuffer writebuf = null;