changeset 111:528b79d1ee35

Cleanup warnings pointed out by findbugs Reviewed-by: vanaltj Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2012-March/000276.html
author Omair Majid <omajid@redhat.com>
date Fri, 09 Mar 2012 12:09:47 -0500
parents ed7314b03796
children 0ba2918dc9d8
files agent/src/main/java/com/redhat/thermostat/agent/config/StartupConfiguration.java client/src/main/java/com/redhat/thermostat/client/ClientArgs.java client/src/main/java/com/redhat/thermostat/client/Main.java client/src/main/java/com/redhat/thermostat/client/ui/RecentTimeSeriesChartController.java client/src/main/java/com/redhat/thermostat/client/ui/SummaryPanel.java common/src/main/java/com/redhat/thermostat/common/dao/MongoConnection.java common/src/main/java/com/redhat/thermostat/common/storage/MongoStorage.java common/src/main/java/com/redhat/thermostat/common/utils/StringUtils.java
diffstat 8 files changed, 52 insertions(+), 45 deletions(-) [+]
line wrap: on
line diff
--- a/agent/src/main/java/com/redhat/thermostat/agent/config/StartupConfiguration.java	Fri Mar 09 11:55:41 2012 -0500
+++ b/agent/src/main/java/com/redhat/thermostat/agent/config/StartupConfiguration.java	Fri Mar 09 12:09:47 2012 -0500
@@ -38,6 +38,7 @@
 
 import java.io.FileReader;
 import java.io.IOException;
+import java.io.Reader;
 import java.net.InetAddress;
 import java.net.UnknownHostException;
 import java.util.ArrayList;
@@ -223,8 +224,8 @@
                     if (index < args.length) {
                         String propFile = args[index];
                         logger.finest("Properties file: " + propFile);
-                        try {
-                            props.load(new FileReader(propFile));
+                        try (Reader reader = new FileReader(propFile)) {
+                            props.load(reader);
                         } catch (IOException ioe) {
                             throw new LaunchException("Unable to read properties file at " + propFile);
                         }
--- a/client/src/main/java/com/redhat/thermostat/client/ClientArgs.java	Fri Mar 09 11:55:41 2012 -0500
+++ b/client/src/main/java/com/redhat/thermostat/client/ClientArgs.java	Fri Mar 09 12:09:47 2012 -0500
@@ -36,14 +36,12 @@
 
 package com.redhat.thermostat.client;
 
-import java.awt.Window;
 import java.io.FileNotFoundException;
 import java.io.FileReader;
 import java.io.IOException;
+import java.io.Reader;
 import java.util.Properties;
 
-import com.redhat.thermostat.client.ui.LayoutDebugHelper;
-
 public class ClientArgs {
 
     private boolean isDebugLayout = Boolean.getBoolean("thermostat.debug-layout");
@@ -59,8 +57,8 @@
                 if (i >= args.length) {
                     throw new IllegalArgumentException("--properties argument requires filename.");
                 }
-                try {
-                    props.load(new FileReader(args[i]));
+                try (Reader reader = new FileReader(args[i])){
+                    props.load(reader);
                 } catch (FileNotFoundException e) {
                     // ignore
                 } catch (IOException e) {
@@ -76,28 +74,6 @@
         // TODO what other arguments do we care about?
         // perhaps skipping the mode selection?
 
-        if (isDebugLayout()) {
-            Thread layoutDebugger = new Thread(new Runnable() {
-                @Override
-                public void run() {
-                    LayoutDebugHelper helper = new LayoutDebugHelper();
-                    while (true) {
-                        try {
-                            Thread.sleep(5000);
-                        } catch (InterruptedException e) {
-                            System.err.println("Layout Debug Helper exiting");
-                        }
-                        Window[] windows = Window.getWindows();
-                        for (Window w : windows) {
-                            helper.debugLayout(w);
-                            w.invalidate();
-                            w.repaint();
-                        }
-                    }
-                }
-            });
-            layoutDebugger.start();
-        }
     }
 
     public boolean isDebugLayout() {
--- a/client/src/main/java/com/redhat/thermostat/client/Main.java	Fri Mar 09 11:55:41 2012 -0500
+++ b/client/src/main/java/com/redhat/thermostat/client/Main.java	Fri Mar 09 12:09:47 2012 -0500
@@ -38,6 +38,7 @@
 
 import static com.redhat.thermostat.client.locale.Translate.localize;
 
+import java.awt.Window;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
@@ -49,6 +50,7 @@
 import com.redhat.thermostat.client.appctx.ApplicationContext;
 import com.redhat.thermostat.client.locale.LocaleResources;
 import com.redhat.thermostat.client.ui.ConnectionSelectionDialog;
+import com.redhat.thermostat.client.ui.LayoutDebugHelper;
 import com.redhat.thermostat.client.ui.MainWindow;
 import com.redhat.thermostat.common.Constants;
 import com.redhat.thermostat.common.dao.Connection;
@@ -117,6 +119,33 @@
         MainWindow gui = new MainWindow(uiFacadeFactory);
         gui.pack();
         gui.setVisible(true);
+
+        if (arguments.isDebugLayout()) {
+            Thread layoutDebugger = new Thread(new Runnable() {
+                @Override
+                public void run() {
+                    LayoutDebugHelper helper = new LayoutDebugHelper();
+                    try {
+                        while (true) {
+                            Thread.sleep(5000);
+                            Window[] windows = Window.getWindows();
+                            for (Window w : windows) {
+                                helper.debugLayout(w);
+                                w.invalidate();
+                                w.repaint();
+                            }
+                        }
+                    } catch (InterruptedException ie) {
+                        logger.log(Level.INFO, "layout debug helper interrupted; exiting", ie);
+                        // mark thread as interrupted
+                        Thread.currentThread().interrupt();
+                    }
+                }
+            });
+            layoutDebugger.setDaemon(true);
+            layoutDebugger.start();
+        }
+
     }
 
     public static void main(String[] args) {
--- a/client/src/main/java/com/redhat/thermostat/client/ui/RecentTimeSeriesChartController.java	Fri Mar 09 11:55:41 2012 -0500
+++ b/client/src/main/java/com/redhat/thermostat/client/ui/RecentTimeSeriesChartController.java	Fri Mar 09 12:09:47 2012 -0500
@@ -44,8 +44,8 @@
 
 public class RecentTimeSeriesChartController {
 
-    private final int DEFAULT_VALUE = 10;
-    private final TimeUnit DEFAULT_UNIT = TimeUnit.MINUTES;
+    private static final int DEFAULT_VALUE = 10;
+    private static final TimeUnit DEFAULT_UNIT = TimeUnit.MINUTES;
 
     private JFreeChart chart;
     private ChartPanel panel;
--- a/client/src/main/java/com/redhat/thermostat/client/ui/SummaryPanel.java	Fri Mar 09 11:55:41 2012 -0500
+++ b/client/src/main/java/com/redhat/thermostat/client/ui/SummaryPanel.java	Fri Mar 09 12:09:47 2012 -0500
@@ -106,7 +106,7 @@
 
         private List<? extends Object> delegate;
 
-        private String emptyElement = new String(localize(LocaleResources.HOME_PANEL_NO_ISSUES));
+        private String emptyElement = localize(LocaleResources.HOME_PANEL_NO_ISSUES);
 
         public IssuesListModel(List<? extends Object> actualList) {
             this.delegate = actualList;
--- a/common/src/main/java/com/redhat/thermostat/common/dao/MongoConnection.java	Fri Mar 09 11:55:41 2012 -0500
+++ b/common/src/main/java/com/redhat/thermostat/common/dao/MongoConnection.java	Fri Mar 09 12:09:47 2012 -0500
@@ -161,7 +161,7 @@
         }
     }
 
-    private class LocalAgentException extends RuntimeException {
+    private static class LocalAgentException extends RuntimeException {
         private static final long serialVersionUID = -4507363475778127729L;
     }
 }
--- a/common/src/main/java/com/redhat/thermostat/common/storage/MongoStorage.java	Fri Mar 09 11:55:41 2012 -0500
+++ b/common/src/main/java/com/redhat/thermostat/common/storage/MongoStorage.java	Fri Mar 09 12:09:47 2012 -0500
@@ -39,6 +39,7 @@
 import java.net.UnknownHostException;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.Map.Entry;
 import java.util.UUID;
 
 import org.bson.BSONObject;
@@ -54,7 +55,7 @@
 
 /**
  * Implementation of the Storage interface that uses MongoDB to store the instrumentation data.
- * 
+ *
  * In this implementation, each CATEGORY is given a distinct collection.
  */
 public class MongoStorage extends Storage {
@@ -162,12 +163,12 @@
                 }
             }
         }
-        for (String mongoKey : nestedParts.keySet()) {
-            toInsert.append(mongoKey, nestedParts.get(mongoKey));
+        for (Entry<String, BasicDBObject> entry: nestedParts.entrySet()) {
+            toInsert.append(entry.getKey(), entry.getValue());
         }
         if (replace) {
-            for (String mongoKey : replaceKeyNestedParts.keySet()) {
-                replaceKey.append(mongoKey, replaceKeyNestedParts.get(mongoKey));
+            for (Entry<String, BasicDBObject> entry: replaceKeyNestedParts.entrySet()) {
+                replaceKey.append(entry.getKey(), entry.getValue());
             }
             coll.update(replaceKey, toInsert, true, false);
         } else {
@@ -220,11 +221,11 @@
                 }
             }
         }
-        for (String mongoKey : nestedParts.keySet()) {
-            toUpdate.append(mongoKey, nestedParts.get(mongoKey));
+        for (Entry<String, BasicDBObject> entry: nestedParts.entrySet()) {
+            toUpdate.append(entry.getKey(), entry.getValue());
         }
-        for (String mongoKey : updateKeyNestedParts.keySet()) {
-            updateKey.append(mongoKey, updateKeyNestedParts.get(mongoKey));
+        for (Entry<String, BasicDBObject> entry: updateKeyNestedParts.entrySet()) {
+            updateKey.append(entry.getKey(), entry.getValue());
         }
         coll.update(updateKey, toUpdate);
     }
@@ -261,8 +262,8 @@
         result.append(StorageConstants.KEY_AGENT_CONFIG_BACKEND_NAME, backend.getName());
         result.append(StorageConstants.KEY_AGENT_CONFIG_BACKEND_DESC, backend.getDescription());
         result.append(StorageConstants.KEY_AGENT_CONFIG_BACKEND_ACTIVE, createBackendActiveDBObject(backend));
-        for (String configName : configMap.keySet()) {
-            result.append(configName, configMap.get(configName));
+        for (Entry<String, String> entry: configMap.entrySet()) {
+            result.append(entry.getKey(), entry.getValue());
         }
         return result;
     }
--- a/common/src/main/java/com/redhat/thermostat/common/utils/StringUtils.java	Fri Mar 09 11:55:41 2012 -0500
+++ b/common/src/main/java/com/redhat/thermostat/common/utils/StringUtils.java	Fri Mar 09 12:09:47 2012 -0500
@@ -55,7 +55,7 @@
     }
 
     public static String quote(String toQuote) {
-        return new String("\"" + toQuote + "\"");
+        return "\"" + toQuote + "\"";
     }
 
     public static String repeat(String text, int times) {