findbugs
authorerik <erik@77661180-640e-0410-b3a8-9f9b13e6d0e0>
Sun, 18 Apr 2010 20:36:22 +0000 (20:36 +0000)
committererik <erik@77661180-640e-0410-b3a8-9f9b13e6d0e0>
Sun, 18 Apr 2010 20:36:22 +0000 (20:36 +0000)
15 files changed:
support/general/src/main/java/org/wamblee/io/SimpleProcess.java
support/spring/src/main/java/org/wamblee/persistence/hibernate/HibernateSupport.java
system/general/src/main/java/org/wamblee/system/adapters/ParameterValues.java
system/general/src/main/java/org/wamblee/system/adapters/SetterConfiguration.java
system/general/src/main/java/org/wamblee/system/core/AbstractComponent.java
system/general/src/main/java/org/wamblee/system/core/DefaultProvidedInterface.java
system/general/src/main/java/org/wamblee/system/core/DefaultRequiredInterface.java
system/general/src/test/java/org/wamblee/system/adapters/AdapterTestCase.java
system/general/src/test/java/org/wamblee/system/adapters/ClassConfigurationTest.java
system/general/src/test/java/org/wamblee/system/adapters/ConstructorConfigurationTest.java
system/general/src/test/java/org/wamblee/system/adapters/SetterConfigurationTest.java
system/general/src/test/java/org/wamblee/system/container/ContainerTest.java
system/general/src/test/java/org/wamblee/system/core/RequiredInterfaceComparator.java
system/general/src/test/java/org/wamblee/system/graph/MyNode.java
system/general/src/test/java/org/wamblee/system/graph/component/ConnectRequiredProvidedEdgeFilterTest.java

index de93e547638d1db49d6c47e57be33665e83d37af..b0e96a90397326a9e8ec8f4c04fce9e34d4c36ad 100644 (file)
@@ -27,6 +27,7 @@ import java.io.OutputStream;
 import java.io.PrintStream;
 import java.io.StringWriter;
 import java.io.Writer;
+import java.util.Arrays;
 
 /**
  * 
@@ -50,7 +51,7 @@ public class SimpleProcess {
      */
     public SimpleProcess(File aDirectory, String[] aCmd) {
         directory = aDirectory;
-        cmd = aCmd;
+        cmd = Arrays.copyOf(aCmd, aCmd.length);
     }
 
     /**
@@ -83,10 +84,10 @@ public class SimpleProcess {
 
     private int runImpl() throws IOException {
         try {
-            String fullcmd = "";
+            StringBuffer fullcmd = new StringBuffer();
 
             for (String part : cmd) {
-                fullcmd += (" " + part);
+                fullcmd.append(" " + part);
             }
 
             LOG.debug("Executing '" + fullcmd + "' in directory '" + directory +
index bd5901eb2c77e645cd53c4200c62f67486fdc8ad..52dbc352b742a8ea2c0552b4b454dccc2b164bfd 100644 (file)
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
- */ 
+ */
 package org.wamblee.persistence.hibernate;
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import org.springframework.orm.hibernate3.HibernateTemplate;
-import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
-
-import org.wamblee.persistence.Persistent;
-
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
-
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.Map.Entry;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.springframework.orm.hibernate3.HibernateTemplate;
+import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
+import org.wamblee.persistence.Persistent;
 
 /**
  * Extension of
@@ -243,21 +241,22 @@ public class HibernateSupport extends HibernateDaoSupport {
      *            List of processed persistent objects.
      * 
      */
-    public static void processMap(Map aPersistent, Map aMerged,
+    public static <Key,Value> void processMap(Map<Key,Value> aPersistent, Map<Key,Value> aMerged,
         List<ObjectElem> aProcessed) {
         if (aMerged.size() != aPersistent.size()) {
             throw new RuntimeException("Sizes differ " + aMerged.size() + " " +
                 aPersistent.size());
         }
 
-        Set keys = aMerged.keySet();
+        Set<Entry<Key,Value>> entries = aMerged.entrySet();
 
-        for (Object key : keys) {
+        for (Entry<Key,Value> entry : entries) {
+            Key key = entry.getKey();
             if (!aPersistent.containsKey(key)) {
                 throw new RuntimeException("Key '" + key + "' not found");
             }
 
-            Object mergedValue = aMerged.get(key);
+            Value mergedValue = entry.getValue();
             Object persistentValue = aPersistent.get(key);
 
             if (mergedValue instanceof Persistent) {
@@ -287,6 +286,12 @@ public class HibernateSupport extends HibernateDaoSupport {
         }
 
         public boolean equals(Object aObj) {
+            if (aObj == null) {
+                return false;
+            }
+            if (!(aObj instanceof ObjectElem)) {
+                return false;
+            }
             return ((ObjectElem) aObj).object == object;
         }
 
index 9c023cb5173c677a116875604fe68a0fae9697ce..27ed495c72909c6f6f7213fb67f56f30b82bb93c 100644 (file)
@@ -20,6 +20,7 @@ import org.wamblee.system.core.RequiredInterface;
 import org.wamblee.system.core.Scope;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
 
 /**
@@ -65,7 +66,7 @@ public class ParameterValues {
     public ParameterValues(String[] aNames, Class[] aTypes) {
         assert aNames.length == aTypes.length;
         names = aNames;
-        types = aTypes;
+        types = Arrays.copyOf(aTypes, aTypes.length);
         resetValues();
     }
 
@@ -75,7 +76,7 @@ public class ParameterValues {
      * @return Types.
      */
     public Class[] getTypes() {
-        return types;
+        return Arrays.copyOf(types, types.length);
     }
 
     /**
index c8baeafb9dcdef0e4b117d49d783c43564712613..fffd828c0f1257135378da5e5dcb81297653e9a0 100644 (file)
@@ -12,7 +12,7 @@
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
- */ 
+ */
 package org.wamblee.system.adapters;
 
 import org.wamblee.collections.CollectionFilter;
@@ -167,7 +167,6 @@ public class SetterConfiguration {
      * 
      */
     public SetterConfiguration add(final String aName) {
-        int oldlen = setters.size();
         List<Method> methods = new ArrayList<Method>();
         CollectionFilter.filter(getAllSetters(clazz, publicOnly), methods,
             new Condition<Method>() {
@@ -222,10 +221,10 @@ public class SetterConfiguration {
         }
 
         if (result.size() > 1) {
-            String setters = "";
+            StringBuffer setters = new StringBuffer();
 
             for (Method method : result) {
-                setters += (method.getName() + " ");
+                setters.append((method.getName() + " "));
             }
 
             throw new IllegalArgumentException(
index ab9751390a2319d5697f7ae80f3db354d3b098d0..1bf835a8b6099a04e4cf98db5f5a38d5cd4e0dbd 100644 (file)
@@ -155,14 +155,14 @@ public abstract class AbstractComponent<Type> implements Component<Type> {
 
     private void checkNotStartedInterfaces() {
         if (remaining.get().size() > 0) {
-            String notProvided = "";
+            StringBuffer notProvided = new StringBuffer();
 
             for (ProvidedInterface provided : remaining.get()) {
-                notProvided += ("\nComponent " + getQualifiedName() +
+                notProvided.append("\nComponent " + getQualifiedName() +
                     " did not start interface " + provided);
             }
 
-            throw new SystemAssemblyException(notProvided);
+            throw new SystemAssemblyException(notProvided.toString());
         }
     }
 
index 165d6ff3c81c1bec8b8bdedb8d807871d0f1b155..b45a19dd1985747b70f6ccfd1034d85bff018456 100644 (file)
@@ -109,12 +109,12 @@ public class DefaultProvidedInterface implements ProvidedInterface {
 
         Collections.sort(result);
 
-        String value = "";
+        StringBuffer value = new StringBuffer();
 
         for (String str : result) {
-            value += (":" + str);
+            value.append(":" + str);
         }
 
-        return value;
+        return value.toString();
     }
 }
index aa4a7253d54823ea1a3e8048e84a6cd18d72b617..b538a22a95188adfeb358b9b1b34219f283ab853 100644 (file)
@@ -166,7 +166,7 @@ public class DefaultRequiredInterface implements RequiredInterface {
 
     @Override
     public int hashCode() {
-        return required.hashCode();
+        return Arrays.hashCode(required);
     }
 
     @Override
index f68e285238419827569c29b4095b6da0a5f111a4..7ca8b96b2cad1ce176a5f41ab3811a0080e083bc 100644 (file)
@@ -41,10 +41,14 @@ public class AdapterTestCase extends TestCase {
         return EVENT_TRACKER;
     }
     
+    private static void setEventTracker(EventTracker<String> aTracker) { 
+        EVENT_TRACKER = aTracker;
+    }
+    
     @Override
     protected void setUp() throws Exception {
         super.setUp();
-        EVENT_TRACKER = new EventTracker<String>();
+        setEventTracker(new EventTracker<String>());
         scope = new DefaultScope(new ProvidedInterface[0]);
     }
 }
index 86e6b077907bebcfa51c21fbaf0ad003d5fa16b6..24a8bae8cd97f122c9e923186c3ff27322365e5c 100644 (file)
@@ -34,9 +34,6 @@ public class ClassConfigurationTest extends AdapterTestCase {
     public void testConstructorConfig() {
         ClassConfiguration classConfig = new ClassConfiguration(X1.class);
 
-        ConstructorConfiguration config = classConfig.getConstructorConfig()
-            .greedy();
-
         ProvidedInterface provided = new DefaultProvidedInterface("arg",
             String.class);
         List<RequiredInterface> required = classConfig.getRequiredInterfaces();
index d1ced96f9b7effb7f3c320203f3cacf0c56cf529..ee57526f3aa1db0c2a66ea3cb9f25a2bb3469697 100644 (file)
@@ -55,6 +55,7 @@ public class ConstructorConfigurationTest extends AdapterTestCase {
         try {
             ConstructorConfiguration config = new ConstructorConfiguration(
                 X2.class).greedy();
+            ignoredVariable(config);        
         } catch (SystemAssemblyException e) {
             // e.printStackTrace();
             return;
@@ -62,6 +63,10 @@ public class ConstructorConfigurationTest extends AdapterTestCase {
 
         fail();
     }
+    
+    private static void ignoredVariable(Object aObject) { 
+        // for findbugs.
+    }
 
     public void testSpecificConstructor() {
         ConstructorConfiguration config = new ConstructorConfiguration(X2.class)
@@ -133,7 +138,6 @@ public class ConstructorConfigurationTest extends AdapterTestCase {
     public void testIgnoredNonPublic() {
         ConstructorConfiguration config = new ConstructorConfiguration(X3.class)
             .greedy();
-        List<RequiredInterface> required = config.getRequiredInterfaces();
         assertEquals(0, config.getParameters().getTypes().length);
     }
 
index 87855d9f9d39d60d7e3fe16a58ff7078022d0f5e..b9b2ac6c0540f0a909ca47153554db15223dabfd 100644 (file)
@@ -275,7 +275,6 @@ public class SetterConfigurationTest extends AdapterTestCase {
     }
 
     public void testAddPrivate() {
-        X5 obj = new X5();
         final SetterConfiguration config = new SetterConfiguration(X5.class);
         AssertionUtils.assertException(new AssertionUtils.ErroneousCode() {
             @Override
index 97c571957aef96716a90f207a259d265aa6f4f5f..2721c5115ec7289747112407214e9620f310c9bc 100644 (file)
@@ -17,6 +17,7 @@ package org.wamblee.system.container;
 
 import junit.framework.TestCase;
 
+import org.junit.internal.requests.IgnoredClassRunner;
 import org.wamblee.general.Pair;
 
 import org.wamblee.system.core.Component;
@@ -222,12 +223,19 @@ public class ContainerTest extends TestCase {
             Component<?> comp = new Application();
             Container system = new Container("top").addComponent(comp);
             Container system2 = new Container("top2").addComponent(comp);
+            
+            ignoredVariable(system);
+            ignoredVariable(system2);
         } catch (SystemAssemblyException e) {
             return;
         }
 
         fail();
     }
+    
+    private static void ignoredVariable(Object aObject) { 
+        // for findbugs.
+    }
 
     public void testCompositeWithExternalDependencesProvided() {
         Component<?> environment = new Environment();
@@ -553,7 +561,7 @@ public class ContainerTest extends TestCase {
         Scope external = new DefaultScope(new ProvidedInterface[0]);
         external.publishInterface(provided, 100);
 
-        Scope scope = container.start(external);
+        container.start(external);
     }
 
     public void testProvidedInterfaces() {
@@ -631,7 +639,7 @@ public class ContainerTest extends TestCase {
         container.getRequiredInterfaces().get(1).setProvider(x);
         container.getRequiredInterfaces().get(2).setProvider(y);
 
-        Scope runtime = container.start(externalScope);
+        container.start(externalScope);
 
         assertEquals("y-value", app.getString());
     }
index ec463aa43e939d35962d575b16a3fdb5d7beb574..79bd2c1a11ac37e3eb7f296393a29371d0bd248d 100644 (file)
@@ -15,6 +15,7 @@
  */ 
 package org.wamblee.system.core;
 
+import java.io.Serializable;
 import java.util.Comparator;
 
 /**
@@ -23,7 +24,10 @@ import java.util.Comparator;
  * @version $Revision$
  */
 public class RequiredInterfaceComparator implements
-    Comparator<RequiredInterface> {
+    Comparator<RequiredInterface>, Serializable {
+    
+    private static final long serialVersionUID = 7631587103378238574L;
+
     @Override
     public int compare(RequiredInterface aO1, RequiredInterface aO2) {
         return aO1.getName().compareTo(aO2.getName());
index e43e683a003d58b0763f5b6d2b7825ef6d614d57..b058896781a9d9474c1f03f9f1fa1cdaf62a3cdd 100644 (file)
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
- */ 
+ */
 package org.wamblee.system.graph;
 
+import java.util.Arrays;
+
 /**
  * 
  * @author $author$
@@ -29,10 +31,26 @@ public class MyNode extends DefaultNode {
      */
     public MyNode(String aName, String[] aPorts) {
         super(aName);
-        ports = aPorts;
+        ports = Arrays.copyOf(aPorts, aPorts.length);
     }
 
     public String[] getPorts() {
-        return ports;
+        return Arrays.copyOf(ports, ports.length);
+    }
+
+    @Override
+    public boolean equals(Object aObj) {
+        if (!super.equals(aObj)) {
+            return false;
+        }
+        if (!(aObj instanceof MyNode)) {
+            return false;
+        }
+        return Arrays.equals(ports, ((MyNode) aObj).ports);
+    }
+    
+    @Override
+    public int hashCode() {
+        return super.hashCode();
     }
 }
index 942eb82bee2c73180c34497ef4ecb68713aefd2c..90c318b04ccd6cdc92ef27f45e0157262c1a7d01 100644 (file)
@@ -72,6 +72,7 @@ public class ConnectRequiredProvidedEdgeFilterTest extends TestCase {
             public void run() throws Exception {
                 EdgeFilter restriction = new ConnectRequiredProvidedEdgeFilter(
                     null, null, null, null);
+                ignoredVariable(restriction);
             }
         }, IllegalArgumentException.class);
         AssertionUtils.assertException(new AssertionUtils.ErroneousCode() {
@@ -79,9 +80,14 @@ public class ConnectRequiredProvidedEdgeFilterTest extends TestCase {
             public void run() throws Exception {
                 EdgeFilter restriction = new ConnectRequiredProvidedEdgeFilter(
                     null, null, "x", "y");
+                ignoredVariable(restriction);
             }
         }, IllegalArgumentException.class);
     }
+    
+    private static final void ignoredVariable(Object aObject) { 
+        // for findbugs.
+    }
 
     public void testClientServer() {
         EdgeFilter restriction = new ConnectRequiredProvidedEdgeFilter("app1",