Bug 1077590 - Part 0: minor sanity fixes in FennecNativeDriver. r=gbrown
☠☠ backed out by 65d55b6ef0df ☠ ☠
authorRichard Newman <rnewman@mozilla.com>
Sun, 11 Jan 2015 17:18:14 -0800
changeset 240014 84aee740b55a35a9ea1c2c2b15f91702cde8a327
parent 240013 3c61d595997e4b80a1eb5e385e7b0ca3fd7d9d96
child 240015 20a66f47634616b532a8632a8ca0a9b13fb75bf8
push id7472
push userraliiev@mozilla.com
push dateMon, 12 Jan 2015 20:36:27 +0000
treeherdermozilla-aurora@300ca104f8fb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgbrown
bugs1077590
milestone37.0a1
Bug 1077590 - Part 0: minor sanity fixes in FennecNativeDriver. r=gbrown
build/mobile/robocop/FennecNativeDriver.java
--- a/build/mobile/robocop/FennecNativeDriver.java
+++ b/build/mobile/robocop/FennecNativeDriver.java
@@ -282,21 +282,23 @@ public class FennecNativeDriver implemen
             while ((line = br.readLine()) != null) {
                 text.append(line);
                 text.append('\n');
             }
         } catch (IOException e) {
             log(LogLevel.ERROR, e);
         } finally {
             try {
-                br.close();
+                if (br != null) {
+                    br.close();
+                }
             } catch (IOException e) {
             }
         }
-        return text.toString();    
+        return text.toString();
     }
 
     /**
      *  Takes a string of "key=value" pairs split by \n and creates a hash table.
      */
     public static Map<String, String> convertTextToTable(String data)
     {
         HashMap<String, String> retVal = new HashMap<String, String>();
@@ -344,37 +346,40 @@ public class FennecNativeDriver implemen
     }
 
     public static void log(LogLevel level, Throwable t) {
         log(level, null, t);
     }
 
     public static void log(LogLevel level, String message, Throwable t) {
         if (mLogFile == null) {
-            assert(false);
+            throw new RuntimeException("No log file specified!");
         }
 
         if (level.isEnabled(mLogLevel)) {
             PrintWriter pw = null;
             try {
                 pw = new PrintWriter(new FileWriter(mLogFile, true));
                 if (message != null) {
                     pw.println(message);
                 }
                 if (t != null) {
                     t.printStackTrace(pw);
                 }
             } catch (IOException ioe) {
                 Log.e("Robocop", "exception with file writer on: " + mLogFile);
             } finally {
-                pw.close();
+                if (pw != null) {
+                    pw.close();
+                }
             }
+
             // PrintWriter doesn't throw IOE but sets an error flag instead,
             // so check for that
-            if (pw.checkError()) {
+            if (pw != null && pw.checkError()) {
                 Log.e("Robocop", "exception with file writer on: " + mLogFile);
             }
         }
 
         if (level == LogLevel.INFO) {
             Log.i("Robocop", message, t);
         } else if (level == LogLevel.DEBUG) {
             Log.d("Robocop", message, t);