Author: henning
Date: Sat Oct  1 03:58:33 2005
New Revision: 292947

URL: http://svn.apache.org/viewcvs?rev=292947&view=rev
Log:
Make sure that the output stream always gets close. Has the side
effect, that getStackTrace will always return the right stack trace as
the IOException can only be thrown in close()

Initialize rs explicitly.

Both problems found by Findbugs.

Modified:
    
jakarta/velocity/core/trunk/src/java/org/apache/velocity/app/event/implement/PrintExceptions.java

Modified: 
jakarta/velocity/core/trunk/src/java/org/apache/velocity/app/event/implement/PrintExceptions.java
URL: 
http://svn.apache.org/viewcvs/jakarta/velocity/core/trunk/src/java/org/apache/velocity/app/event/implement/PrintExceptions.java?rev=292947&r1=292946&r2=292947&view=diff
==============================================================================
--- 
jakarta/velocity/core/trunk/src/java/org/apache/velocity/app/event/implement/PrintExceptions.java
 (original)
+++ 
jakarta/velocity/core/trunk/src/java/org/apache/velocity/app/event/implement/PrintExceptions.java
 Sat Oct  1 03:58:33 2005
@@ -42,7 +42,9 @@
 
     private static String SHOW_MESSAGE = 
"eventhandler.methodexception.message";
     private static String SHOW_STACK_TRACE = 
"eventhandler.methodexception.stacktrace";
-    private RuntimeServices rs;
+
+    /** Reference to the runtime service */
+    private RuntimeServices rs = null;
 
     /**
      * Render the method exception, and optionally the exception message and 
stack trace.
@@ -83,23 +85,31 @@
     }
 
 
-    private static String getStackTrace(Throwable E)
+    private static String getStackTrace(Throwable throwable)
     {
+        StringWriter stackTraceWriter = null;
         try
         {
-            StringWriter StackTraceWriter = new StringWriter();
-            E.printStackTrace(new PrintWriter(StackTraceWriter));
-            StackTraceWriter.flush();
-            String StackTrace = StackTraceWriter.toString();
-            StackTraceWriter.close();
-            return StackTraceWriter.toString() ;
+            stackTraceWriter = new StringWriter();
+            throwable.printStackTrace(new PrintWriter(stackTraceWriter));
+            stackTraceWriter.flush();
+            return stackTraceWriter.toString();
         }
-        catch (IOException ioe)
+        finally
         {
-            return "";
+            if (stackTraceWriter != null)
+            {
+                try
+                {
+                    stackTraceWriter.close();
+                }
+                catch (IOException ioe)
+                {
+                    // do nothing
+                }
+            }
         }
     }
-
 
 
     public void setRuntimeServices(RuntimeServices rs) throws Exception



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to