forms/qa/integration/forms/FormControlTest.java                            |   
14 +-
 xmerge/source/xmerge/java/org/openoffice/xmerge/util/ActiveSyncDriver.java |   
61 +++++-----
 xmerge/source/xmerge/java/org/openoffice/xmerge/util/Debug.java            |   
48 ++++---
 3 files changed, 70 insertions(+), 53 deletions(-)

New commits:
commit bbd5a304112c57ac1b1357c93ba7bd8ed8973cfa
Author: Robert Antoni Buj i Gelonch <robert....@gmail.com>
Date:   Wed Oct 15 21:48:19 2014 +0200

    java: ensure that the stream is cleaned up before the method returns
    
    Change-Id: Id3efeda2fd66173ba2f5662eaacb3629da54573d
    Reviewed-on: https://gerrit.libreoffice.org/11991
    Reviewed-by: Noel Grandin <noelgran...@gmail.com>
    Tested-by: Noel Grandin <noelgran...@gmail.com>

diff --git a/forms/qa/integration/forms/FormControlTest.java 
b/forms/qa/integration/forms/FormControlTest.java
index d574640..b7dacb7 100644
--- a/forms/qa/integration/forms/FormControlTest.java
+++ b/forms/qa/integration/forms/FormControlTest.java
@@ -868,9 +868,17 @@ public class FormControlTest extends 
complexlib.ComplexTestCase implements XSQLE
     {
         m_sImageURL = util.utils.getOfficeTempDir( m_orb ) + "image.gif";
 
-        FileOutputStream aFile = new FileOutputStream( m_sImageURL );
-        aFile.write( getSamplePicture() );
-        aFile.close();
+        FileOutputStream aFile = null;
+        try
+        {
+            aFile = new FileOutputStream( m_sImageURL );
+            aFile.write( getSamplePicture() );
+        }
+        finally
+        {
+            if ( aFile != null )
+                aFile.close();
+        }
         log.println( "created temporary image file: " + m_sImageURL );
 
         // for later setting the url at the imaghe control, we need a real 
URL, no system path
diff --git 
a/xmerge/source/xmerge/java/org/openoffice/xmerge/util/ActiveSyncDriver.java 
b/xmerge/source/xmerge/java/org/openoffice/xmerge/util/ActiveSyncDriver.java
index e10702a..8299632 100644
--- a/xmerge/source/xmerge/java/org/openoffice/xmerge/util/ActiveSyncDriver.java
+++ b/xmerge/source/xmerge/java/org/openoffice/xmerge/util/ActiveSyncDriver.java
@@ -21,11 +21,15 @@ package org.openoffice.xmerge.util;
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.FileInputStream;
+import java.io.IOException;
+
 import java.util.StringTokenizer;
+import java.util.NoSuchElementException;
 
 import org.openoffice.xmerge.Convert;
 import org.openoffice.xmerge.Document;
 import org.openoffice.xmerge.ConvertData;
+import org.openoffice.xmerge.ConvertException;
 import org.openoffice.xmerge.ConverterFactory;
 import org.openoffice.xmerge.util.registry.ConverterInfoMgr;
 import org.openoffice.xmerge.util.registry.ConverterInfoReader;
@@ -103,36 +107,37 @@ public class ActiveSyncDriver {
         }
 
         // Everything is registered so do the conversion
-        FileInputStream fis = new FileInputStream(srcFile);
-        FileOutputStream fos = new FileOutputStream(dstFile);
-
-        conv.addInputStream(srcFile, fis);
-
-        ConvertData dataOut;
+        boolean bOK = true;
+        FileInputStream fis = null;
+        FileOutputStream fos = null;
         try {
-            dataOut = conv.convert();
-        }
-        catch (Exception e) {
-            fos.close();
-            return false;
-        }
-
-        if (dataOut == null) {
-            fos.close();
-            return false;
-        }
-
-        // Get the document and write it out.
-        Document doc = (Document)dataOut.getDocumentEnumeration().next();
-        if (doc == null) {
-            fos.close();
-            return false;
+            fis = new FileInputStream(srcFile);
+            conv.addInputStream(srcFile, fis);
+            try {
+                fos = new FileOutputStream(dstFile);
+                ConvertData dataOut = conv.convert();
+
+                // Get the document and write it out.
+                Document doc = 
(Document)dataOut.getDocumentEnumeration().next();
+                doc.write(fos);
+                fos.flush();
+            } finally {
+                if (fos != null)
+                    fos.close();
+            }
+        } catch (IOException e) {
+            bOK = false;
+        } catch (NullPointerException e) {
+            bOK = false;
+        } catch (ConvertException e) {
+            bOK = false;
+        } catch (NoSuchElementException e) {
+            bOK = false;
+        } finally {
+            if (fis != null)
+                fis.close();
         }
 
-        doc.write(fos);
-        fos.flush();
-        fos.close();
-
-        return true;
+        return bOK;
     }
 }
\ No newline at end of file
diff --git a/xmerge/source/xmerge/java/org/openoffice/xmerge/util/Debug.java 
b/xmerge/source/xmerge/java/org/openoffice/xmerge/util/Debug.java
index fe0429e..50a34b2 100644
--- a/xmerge/source/xmerge/java/org/openoffice/xmerge/util/Debug.java
+++ b/xmerge/source/xmerge/java/org/openoffice/xmerge/util/Debug.java
@@ -53,38 +53,42 @@ public final class Debug {
 
     static {
 
+        InputStream is = null;
         try {
+            try {
+                is = Debug.class.getResourceAsStream("Debug.properties");
+                Properties props = new Properties();
+                props.load(is);
 
-            InputStream is = 
Debug.class.getResourceAsStream("Debug.properties");
-            Properties props = new Properties();
-            props.load(is);
+                String info = props.getProperty("debug.info", "false");
+                info = info.toLowerCase();
 
-            String info = props.getProperty("debug.info", "false");
-            info = info.toLowerCase();
-
-            if (info.equals("true")) {
-                setFlags(Debug.INFO, Debug.SET);
-            }
+                if (info.equals("true")) {
+                    setFlags(Debug.INFO, Debug.SET);
+                }
 
-            String trace = props.getProperty("debug.trace", "false");
-            trace = trace.toLowerCase();
+                String trace = props.getProperty("debug.trace", "false");
+                trace = trace.toLowerCase();
 
-            if (trace.equals("true")) {
-                setFlags(Debug.TRACE, Debug.SET);
-            }
+                if (trace.equals("true")) {
+                    setFlags(Debug.TRACE, Debug.SET);
+                }
 
-            String error = props.getProperty("debug.error", "false");
-            error = error.toLowerCase();
+                String error = props.getProperty("debug.error", "false");
+                error = error.toLowerCase();
 
-            if (error.equals("true")) {
-                setFlags(Debug.ERROR, Debug.SET);
-            }
+                if (error.equals("true")) {
+                    setFlags(Debug.ERROR, Debug.SET);
+                }
 
-            String w = props.getProperty("debug.output", "System.out");
-            setOutput(w);
+                String w = props.getProperty("debug.output", "System.out");
+                setOutput(w);
 
+            } finally {
+                if (is !=null)
+                    is.close();
+            }
         } catch (Throwable ex) {
-
             ex.printStackTrace(System.err);
         }
     }
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to