You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2010/12/07 19:36:39 UTC

svn commit: r1043157 - in /tomcat/trunk/java: javax/el/ExpressionFactory.java org/apache/catalina/core/StandardContext.java org/apache/jasper/compiler/JDTCompiler.java org/apache/tomcat/util/net/NioEndpoint.java

Author: markt
Date: Tue Dec  7 18:36:39 2010
New Revision: 1043157

URL: http://svn.apache.org/viewvc?rev=1043157&view=rev
Log:
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.

Modified:
    tomcat/trunk/java/javax/el/ExpressionFactory.java
    tomcat/trunk/java/org/apache/catalina/core/StandardContext.java
    tomcat/trunk/java/org/apache/jasper/compiler/JDTCompiler.java
    tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java

Modified: tomcat/trunk/java/javax/el/ExpressionFactory.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/javax/el/ExpressionFactory.java?rev=1043157&r1=1043156&r2=1043157&view=diff
==============================================================================
--- tomcat/trunk/java/javax/el/ExpressionFactory.java (original)
+++ tomcat/trunk/java/javax/el/ExpressionFactory.java Tue Dec  7 18:36:39 2010
@@ -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*/}
             }
         }
         

Modified: tomcat/trunk/java/org/apache/catalina/core/StandardContext.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/StandardContext.java?rev=1043157&r1=1043156&r2=1043157&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/core/StandardContext.java (original)
+++ tomcat/trunk/java/org/apache/catalina/core/StandardContext.java Tue Dec  7 18:36:39 2010
@@ -5897,21 +5897,26 @@ public class StandardContext extends Con
         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(); 
-    
     }
     
     

Modified: tomcat/trunk/java/org/apache/jasper/compiler/JDTCompiler.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/jasper/compiler/JDTCompiler.java?rev=1043157&r1=1043156&r2=1043157&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/jasper/compiler/JDTCompiler.java (original)
+++ tomcat/trunk/java/org/apache/jasper/compiler/JDTCompiler.java Tue Dec  7 18:36:39 2010
@@ -98,17 +98,21 @@ public class JDTCompiler extends org.apa
                 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.apa
                 } 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.apa
                 return className.toCharArray();
             }
             
+            @Override
             public char[][] getPackageName() {
                 StringTokenizer izer = 
                     new StringTokenizer(className, ".");
@@ -154,6 +163,7 @@ public class JDTCompiler extends org.apa
 
         final INameEnvironment env = new INameEnvironment() {
 
+                @Override
                 public NameEnvironmentAnswer 
                     findType(char[][] compoundTypeName) {
                     String result = "";
@@ -166,6 +176,7 @@ public class JDTCompiler extends org.apa
                     return findType(result);
                 }
 
+                @Override
                 public NameEnvironmentAnswer 
                     findType(char[] typeName, 
                              char[][] packageName) {
@@ -238,6 +249,7 @@ public class JDTCompiler extends org.apa
                     return is == null;
                 }
 
+                @Override
                 public boolean isPackage(char[][] parentPackageName, 
                                          char[] packageName) {
                     String result = "";
@@ -261,6 +273,7 @@ public class JDTCompiler extends org.apa
                     return isPackage(result);
                 }
 
+                @Override
                 public void cleanup() {
                 }
 
@@ -367,6 +380,7 @@ public class JDTCompiler extends org.apa
             new DefaultProblemFactory(Locale.getDefault());
         
         final ICompilerRequestor requestor = new ICompilerRequestor() {
+                @Override
                 public void acceptResult(CompilationResult result) {
                     try {
                         if (result.hasProblems()) {

Modified: tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java?rev=1043157&r1=1043156&r2=1043157&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java Tue Dec  7 18:36:39 2010
@@ -492,13 +492,33 @@ public class NioEndpoint extends Abstrac
             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 Abstrac
      * 
      * 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 Abstrac
     }
 
     // ------------------------------------------------ Application Buffer Handler
-    public class NioBufferHandler implements ApplicationBufferHandler {
+    public static class NioBufferHandler implements ApplicationBufferHandler {
         protected ByteBuffer readbuf = null;
         protected ByteBuffer writebuf = null;
         



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org