OSDN Git Service

fix 3 potential problems detected by FindBugs
authorargius <argius.net@gmail.com>
Fri, 28 Nov 2014 14:11:08 +0000 (23:11 +0900)
committerargius <argius.net@gmail.com>
Fri, 28 Nov 2014 14:11:08 +0000 (23:11 +0900)
src/net/argius/stew/DaemonThreadFactory.java
src/net/argius/stew/ResourceManager.java
src/net/argius/stew/ui/window/WindowLauncher.java

index e9336cf..245ea61 100644 (file)
@@ -1,6 +1,7 @@
 package net.argius.stew;
 
 import java.util.concurrent.*;
+import java.util.concurrent.atomic.*;
 
 /**
  * This is a ThreadFactory which creates threads as a daemon.
@@ -8,8 +9,8 @@ import java.util.concurrent.*;
 public final class DaemonThreadFactory implements ThreadFactory {
 
     private static final Logger log = Logger.getLogger(DaemonThreadFactory.class);
+    private static final AtomicInteger count = new AtomicInteger();
 
-    private static volatile int count;
     private static volatile ThreadFactory instance;
 
     private DaemonThreadFactory() {
@@ -28,7 +29,7 @@ public final class DaemonThreadFactory implements ThreadFactory {
 
     @Override
     public Thread newThread(Runnable r) {
-        final String name = String.format("ChildDaemon%d-of-%s", count++, Thread.currentThread());
+        final String name = String.format("ChildDaemon%d-of-%s", count.getAndIncrement(), Thread.currentThread());
         if (log.isDebugEnabled()) {
             log.debug("create thread: name=" + name);
         }
index 76f6fa3..5c5888f 100644 (file)
@@ -34,15 +34,13 @@ public final class ResourceManager {
         for (final String name : getResourceNames(o)) {
             for (final String suffix : suffixes) {
                 final String key = name + suffix;
-                Map<String, String> m = ResourceManager0.map.get(key);
-                if (m == null) {
-                    m = loadResource(key, "u8p", "utf-8");
-                    if (m == null) {
-                        continue;
-                    }
-                    ResourceManager0.map.putIfAbsent(key, m);
+                Map<String, String> m = (ResourceManager0.map.containsKey(key))
+                        ? ResourceManager0.map.get(key)
+                        : loadResource(key, "u8p", "utf-8");
+                if (m != null) {
+                    ResourceManager0.map.put(key, m);
+                    a.add(m);
                 }
-                a.add(m);
             }
         }
         return new ResourceManager(a);
index bdc8bef..851919f 100644 (file)
@@ -6,7 +6,6 @@ import static javax.swing.JSplitPane.VERTICAL_SPLIT;
 import static javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER;
 import static javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS;
 import static net.argius.stew.ui.window.AnyActionKey.*;
-
 import java.awt.*;
 import java.awt.event.*;
 import java.beans.*;
@@ -18,12 +17,10 @@ import java.util.Map.Entry;
 import java.util.List;
 import java.util.Timer;
 import java.util.concurrent.*;
-
 import javax.swing.*;
 import javax.swing.event.*;
 import javax.swing.table.*;
 import javax.swing.text.*;
-
 import net.argius.stew.*;
 import net.argius.stew.ui.*;
 
@@ -121,7 +118,7 @@ public final class WindowLauncher implements
         statusBar.setForeground(Color.BLUE);
         // [Layouts]
         /*
-         * split2 = ResultSetTable + TextArea 
+         * split2 = ResultSetTable + TextArea
          * +----------------------------+
          * | split2                     |
          * | +------------------------+ |
@@ -765,6 +762,7 @@ public final class WindowLauncher implements
             final DatabaseInfoTree infoTree = this.infoTree;
             final JLabel statusBar = this.statusBar;
             final OutputProcessor opref = env.getOutputProcessor();
+            final AnyAction invoker = new AnyAction(this);
             try {
                 doPreProcess();
                 executorService.execute(new Runnable() {
@@ -790,14 +788,9 @@ public final class WindowLauncher implements
                         if (env.getOutputProcessor() == opref) {
                             time = System.currentTimeMillis() - time;
                             statusBar.setText(res.get("i.statusbar-message", time / 1000f, cmd));
-                            AnyAction invoker = new AnyAction(this);
-                            invoker.doLater("callDoPostProcess");
+                            invoker.doLater("doPostProcess");
                         }
                     }
-                    @SuppressWarnings("unused")
-                    void callDoPostProcess() {
-                        WindowLauncher.this.doPostProcess();
-                    }
                 });
             } catch (Exception ex) {
                 throw new RuntimeException(ex);