cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fel...@apache.org
Subject svn commit: r591592 - in /cocoon/trunk: blocks/cocoon-chaperon/cocoon-chaperon-impl/src/main/java/org/apache/cocoon/generation/ blocks/cocoon-slop/cocoon-slop-impl/src/main/java/org/apache/cocoon/slop/generation/ blocks/cocoon-xsp/cocoon-xsp-impl/src/m...
Date Sat, 03 Nov 2007 11:09:22 GMT
Author: felixk
Date: Sat Nov  3 04:09:21 2007
New Revision: 591592

URL: http://svn.apache.org/viewvc?rev=591592&view=rev
Log:
Method may fail to close stream

The method creates an IO stream object, does not assign it to any fields, pass it to other
methods that might close it, or return it, and does not appear to close the stream on all
paths out of the method.  This may result in a file descriptor leak.  It is generally a good
idea to use a finally block to ensure that streams are closed.

Modified:
    cocoon/trunk/blocks/cocoon-chaperon/cocoon-chaperon-impl/src/main/java/org/apache/cocoon/generation/TextGenerator.java
    cocoon/trunk/blocks/cocoon-slop/cocoon-slop-impl/src/main/java/org/apache/cocoon/slop/generation/SlopGenerator.java
    cocoon/trunk/blocks/cocoon-xsp/cocoon-xsp-impl/src/main/java/org/apache/cocoon/components/language/programming/java/EclipseJavaCompiler.java
    cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/main/java/org/apache/cocoon/spring/configurator/impl/SettingsBeanFactoryPostProcessor.java

Modified: cocoon/trunk/blocks/cocoon-chaperon/cocoon-chaperon-impl/src/main/java/org/apache/cocoon/generation/TextGenerator.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-chaperon/cocoon-chaperon-impl/src/main/java/org/apache/cocoon/generation/TextGenerator.java?rev=591592&r1=591591&r2=591592&view=diff
==============================================================================
--- cocoon/trunk/blocks/cocoon-chaperon/cocoon-chaperon-impl/src/main/java/org/apache/cocoon/generation/TextGenerator.java
(original)
+++ cocoon/trunk/blocks/cocoon-chaperon/cocoon-chaperon-impl/src/main/java/org/apache/cocoon/generation/TextGenerator.java
Sat Nov  3 04:09:21 2007
@@ -198,28 +198,32 @@
     contentHandler.startElement(URI, "text", "text", atts);
 
     LineNumberReader reader = new LineNumberReader(in);
-    String line;
-    String newline = null;
-
-    while (true) {
-      if (newline==null) {
-        line = convertNonXmlChars(reader.readLine());
-      } else {
-        line = newline;
-      }
-      if (line==null) {
-        break;
-      }
-      newline = convertNonXmlChars(reader.readLine());
-      if (newline != null) {
-          line += SystemUtils.LINE_SEPARATOR;
-      }
-      locator.setLineNumber(reader.getLineNumber());
-      locator.setColumnNumber(1);
-      contentHandler.characters(line.toCharArray(), 0, line.length());
-      if (newline==null) {
-        break;
-      }
+    try {
+        String line;
+        String newline = null;
+    
+        while (true) {
+          if (newline==null) {
+            line = convertNonXmlChars(reader.readLine());
+          } else {
+            line = newline;
+          }
+          if (line==null) {
+            break;
+          }
+          newline = convertNonXmlChars(reader.readLine());
+          if (newline != null) {
+              line += SystemUtils.LINE_SEPARATOR;
+          }
+          locator.setLineNumber(reader.getLineNumber());
+          locator.setColumnNumber(1);
+          contentHandler.characters(line.toCharArray(), 0, line.length());
+          if (newline==null) {
+            break;
+          }
+        }
+    } finally {
+        reader.close();
     }
     contentHandler.endElement(URI, "text", "text");
     contentHandler.endPrefixMapping("");

Modified: cocoon/trunk/blocks/cocoon-slop/cocoon-slop-impl/src/main/java/org/apache/cocoon/slop/generation/SlopGenerator.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-slop/cocoon-slop-impl/src/main/java/org/apache/cocoon/slop/generation/SlopGenerator.java?rev=591592&r1=591591&r2=591592&view=diff
==============================================================================
--- cocoon/trunk/blocks/cocoon-slop/cocoon-slop-impl/src/main/java/org/apache/cocoon/slop/generation/SlopGenerator.java
(original)
+++ cocoon/trunk/blocks/cocoon-slop/cocoon-slop-impl/src/main/java/org/apache/cocoon/slop/generation/SlopGenerator.java
Sat Nov  3 04:09:21 2007
@@ -159,28 +159,32 @@
         parser.startDocument(contentHandler);
 
         LineNumberReader reader = new LineNumberReader(in);
-        String line, newline = null;
-
-        while (true) {
-            if (newline == null) {
-                line = reader.readLine();
-            } else {
-                line = newline;
-            }
-
-            if (line == null) {
-                break;
-            }
-
-            newline = reader.readLine();
-
-            locator.setLineNumber(reader.getLineNumber());
-            locator.setColumnNumber(1);
-            parser.processLine(line);
-
-            if (newline == null) {
-                break;
+        try {
+            String line, newline = null;
+    
+            while (true) {
+                if (newline == null) {
+                    line = reader.readLine();
+                } else {
+                    line = newline;
+                }
+    
+                if (line == null) {
+                    break;
+                }
+    
+                newline = reader.readLine();
+    
+                locator.setLineNumber(reader.getLineNumber());
+                locator.setColumnNumber(1);
+                parser.processLine(line);
+    
+                if (newline == null) {
+                    break;
+                }
             }
+        } finally {
+            reader.close();
         }
 
         // done parsing

Modified: cocoon/trunk/blocks/cocoon-xsp/cocoon-xsp-impl/src/main/java/org/apache/cocoon/components/language/programming/java/EclipseJavaCompiler.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-xsp/cocoon-xsp-impl/src/main/java/org/apache/cocoon/components/language/programming/java/EclipseJavaCompiler.java?rev=591592&r1=591591&r2=591592&view=diff
==============================================================================
--- cocoon/trunk/blocks/cocoon-xsp/cocoon-xsp-impl/src/main/java/org/apache/cocoon/components/language/programming/java/EclipseJavaCompiler.java
(original)
+++ cocoon/trunk/blocks/cocoon-xsp/cocoon-xsp-impl/src/main/java/org/apache/cocoon/components/language/programming/java/EclipseJavaCompiler.java
Sat Nov  3 04:09:21 2007
@@ -181,16 +181,20 @@
                 FileReader fr = null;
                 try {
                     fr = new FileReader(sourceFile);
-                    Reader reader = new BufferedReader(fr);
-                    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);
+                    final Reader reader = new BufferedReader(fr);
+                    try {
+                        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);
                         }
-                        result = new char[buf.length()];
-                        buf.getChars(0, result.length, result, 0);
+                    } finally {
+                        reader.close();
                     }
                 } catch (IOException e) {
                     handleError(className, -1, -1, e.getMessage());

Modified: cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/main/java/org/apache/cocoon/spring/configurator/impl/SettingsBeanFactoryPostProcessor.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/main/java/org/apache/cocoon/spring/configurator/impl/SettingsBeanFactoryPostProcessor.java?rev=591592&r1=591591&r2=591592&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/main/java/org/apache/cocoon/spring/configurator/impl/SettingsBeanFactoryPostProcessor.java
(original)
+++ cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/main/java/org/apache/cocoon/spring/configurator/impl/SettingsBeanFactoryPostProcessor.java
Sat Nov  3 04:09:21 2007
@@ -214,7 +214,15 @@
                 }
                 try {
                     final FileInputStream fis = new FileInputStream(fileName);
-                    properties.load(fis);
+                    try {
+                        properties.load(fis);
+                    } finally {
+                        try {
+                            fis.close();
+                        } catch (IOException ioe) {
+                            this.logger.warn("Failed to close FileInputStream:", ioe);
+                        }
+                    }
                 } catch (IOException ignore) {
                     this.logger.info("Unable to read '" + fileName + "' - continuing with
initialization.", ignore);
                 }



Mime
View raw message