From: argius Date: Fri, 28 Nov 2014 14:11:08 +0000 (+0900) Subject: fix 3 potential problems detected by FindBugs X-Git-Tag: v4.2.0-beta1~3 X-Git-Url: http://git.osdn.net/view?p=stew%2FStew4.git;a=commitdiff_plain;h=71496e527056416ea18b22bda305c04638c39f3d fix 3 potential problems detected by FindBugs --- diff --git a/src/net/argius/stew/DaemonThreadFactory.java b/src/net/argius/stew/DaemonThreadFactory.java index e9336cf..245ea61 100644 --- a/src/net/argius/stew/DaemonThreadFactory.java +++ b/src/net/argius/stew/DaemonThreadFactory.java @@ -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); } diff --git a/src/net/argius/stew/ResourceManager.java b/src/net/argius/stew/ResourceManager.java index 76f6fa3..5c5888f 100644 --- a/src/net/argius/stew/ResourceManager.java +++ b/src/net/argius/stew/ResourceManager.java @@ -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 m = ResourceManager0.map.get(key); - if (m == null) { - m = loadResource(key, "u8p", "utf-8"); - if (m == null) { - continue; - } - ResourceManager0.map.putIfAbsent(key, m); + Map 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); diff --git a/src/net/argius/stew/ui/window/WindowLauncher.java b/src/net/argius/stew/ui/window/WindowLauncher.java index bdc8bef..851919f 100644 --- a/src/net/argius/stew/ui/window/WindowLauncher.java +++ b/src/net/argius/stew/ui/window/WindowLauncher.java @@ -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);