From: erik Date: Sun, 18 Apr 2010 20:36:22 +0000 (+0000) Subject: findbugs X-Git-Tag: wamblee-utils-0.2.2^2~62 X-Git-Url: http://wamblee.org/gitweb/?a=commitdiff_plain;h=932cbb5d442a8172440e197fcae2a0399c27ce15;p=utils findbugs --- diff --git a/support/general/src/main/java/org/wamblee/io/SimpleProcess.java b/support/general/src/main/java/org/wamblee/io/SimpleProcess.java index de93e547..b0e96a90 100644 --- a/support/general/src/main/java/org/wamblee/io/SimpleProcess.java +++ b/support/general/src/main/java/org/wamblee/io/SimpleProcess.java @@ -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 + diff --git a/support/spring/src/main/java/org/wamblee/persistence/hibernate/HibernateSupport.java b/support/spring/src/main/java/org/wamblee/persistence/hibernate/HibernateSupport.java index bd5901eb..52dbc352 100644 --- a/support/spring/src/main/java/org/wamblee/persistence/hibernate/HibernateSupport.java +++ b/support/spring/src/main/java/org/wamblee/persistence/hibernate/HibernateSupport.java @@ -12,24 +12,22 @@ * 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 void processMap(Map aPersistent, Map aMerged, List aProcessed) { if (aMerged.size() != aPersistent.size()) { throw new RuntimeException("Sizes differ " + aMerged.size() + " " + aPersistent.size()); } - Set keys = aMerged.keySet(); + Set> entries = aMerged.entrySet(); - for (Object key : keys) { + for (Entry 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; } diff --git a/system/general/src/main/java/org/wamblee/system/adapters/ParameterValues.java b/system/general/src/main/java/org/wamblee/system/adapters/ParameterValues.java index 9c023cb5..27ed495c 100644 --- a/system/general/src/main/java/org/wamblee/system/adapters/ParameterValues.java +++ b/system/general/src/main/java/org/wamblee/system/adapters/ParameterValues.java @@ -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); } /** diff --git a/system/general/src/main/java/org/wamblee/system/adapters/SetterConfiguration.java b/system/general/src/main/java/org/wamblee/system/adapters/SetterConfiguration.java index c8baeafb..fffd828c 100644 --- a/system/general/src/main/java/org/wamblee/system/adapters/SetterConfiguration.java +++ b/system/general/src/main/java/org/wamblee/system/adapters/SetterConfiguration.java @@ -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 methods = new ArrayList(); CollectionFilter.filter(getAllSetters(clazz, publicOnly), methods, new Condition() { @@ -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( diff --git a/system/general/src/main/java/org/wamblee/system/core/AbstractComponent.java b/system/general/src/main/java/org/wamblee/system/core/AbstractComponent.java index ab975139..1bf835a8 100644 --- a/system/general/src/main/java/org/wamblee/system/core/AbstractComponent.java +++ b/system/general/src/main/java/org/wamblee/system/core/AbstractComponent.java @@ -155,14 +155,14 @@ public abstract class AbstractComponent implements Component { 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()); } } diff --git a/system/general/src/main/java/org/wamblee/system/core/DefaultProvidedInterface.java b/system/general/src/main/java/org/wamblee/system/core/DefaultProvidedInterface.java index 165d6ff3..b45a19dd 100644 --- a/system/general/src/main/java/org/wamblee/system/core/DefaultProvidedInterface.java +++ b/system/general/src/main/java/org/wamblee/system/core/DefaultProvidedInterface.java @@ -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(); } } diff --git a/system/general/src/main/java/org/wamblee/system/core/DefaultRequiredInterface.java b/system/general/src/main/java/org/wamblee/system/core/DefaultRequiredInterface.java index aa4a7253..b538a22a 100644 --- a/system/general/src/main/java/org/wamblee/system/core/DefaultRequiredInterface.java +++ b/system/general/src/main/java/org/wamblee/system/core/DefaultRequiredInterface.java @@ -166,7 +166,7 @@ public class DefaultRequiredInterface implements RequiredInterface { @Override public int hashCode() { - return required.hashCode(); + return Arrays.hashCode(required); } @Override diff --git a/system/general/src/test/java/org/wamblee/system/adapters/AdapterTestCase.java b/system/general/src/test/java/org/wamblee/system/adapters/AdapterTestCase.java index f68e2852..7ca8b96b 100644 --- a/system/general/src/test/java/org/wamblee/system/adapters/AdapterTestCase.java +++ b/system/general/src/test/java/org/wamblee/system/adapters/AdapterTestCase.java @@ -41,10 +41,14 @@ public class AdapterTestCase extends TestCase { return EVENT_TRACKER; } + private static void setEventTracker(EventTracker aTracker) { + EVENT_TRACKER = aTracker; + } + @Override protected void setUp() throws Exception { super.setUp(); - EVENT_TRACKER = new EventTracker(); + setEventTracker(new EventTracker()); scope = new DefaultScope(new ProvidedInterface[0]); } } diff --git a/system/general/src/test/java/org/wamblee/system/adapters/ClassConfigurationTest.java b/system/general/src/test/java/org/wamblee/system/adapters/ClassConfigurationTest.java index 86e6b077..24a8bae8 100644 --- a/system/general/src/test/java/org/wamblee/system/adapters/ClassConfigurationTest.java +++ b/system/general/src/test/java/org/wamblee/system/adapters/ClassConfigurationTest.java @@ -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 required = classConfig.getRequiredInterfaces(); diff --git a/system/general/src/test/java/org/wamblee/system/adapters/ConstructorConfigurationTest.java b/system/general/src/test/java/org/wamblee/system/adapters/ConstructorConfigurationTest.java index d1ced96f..ee57526f 100644 --- a/system/general/src/test/java/org/wamblee/system/adapters/ConstructorConfigurationTest.java +++ b/system/general/src/test/java/org/wamblee/system/adapters/ConstructorConfigurationTest.java @@ -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 required = config.getRequiredInterfaces(); assertEquals(0, config.getParameters().getTypes().length); } diff --git a/system/general/src/test/java/org/wamblee/system/adapters/SetterConfigurationTest.java b/system/general/src/test/java/org/wamblee/system/adapters/SetterConfigurationTest.java index 87855d9f..b9b2ac6c 100644 --- a/system/general/src/test/java/org/wamblee/system/adapters/SetterConfigurationTest.java +++ b/system/general/src/test/java/org/wamblee/system/adapters/SetterConfigurationTest.java @@ -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 diff --git a/system/general/src/test/java/org/wamblee/system/container/ContainerTest.java b/system/general/src/test/java/org/wamblee/system/container/ContainerTest.java index 97c57195..2721c511 100644 --- a/system/general/src/test/java/org/wamblee/system/container/ContainerTest.java +++ b/system/general/src/test/java/org/wamblee/system/container/ContainerTest.java @@ -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()); } diff --git a/system/general/src/test/java/org/wamblee/system/core/RequiredInterfaceComparator.java b/system/general/src/test/java/org/wamblee/system/core/RequiredInterfaceComparator.java index ec463aa4..79bd2c1a 100644 --- a/system/general/src/test/java/org/wamblee/system/core/RequiredInterfaceComparator.java +++ b/system/general/src/test/java/org/wamblee/system/core/RequiredInterfaceComparator.java @@ -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 { + Comparator, Serializable { + + private static final long serialVersionUID = 7631587103378238574L; + @Override public int compare(RequiredInterface aO1, RequiredInterface aO2) { return aO1.getName().compareTo(aO2.getName()); diff --git a/system/general/src/test/java/org/wamblee/system/graph/MyNode.java b/system/general/src/test/java/org/wamblee/system/graph/MyNode.java index e43e683a..b0588967 100644 --- a/system/general/src/test/java/org/wamblee/system/graph/MyNode.java +++ b/system/general/src/test/java/org/wamblee/system/graph/MyNode.java @@ -12,9 +12,11 @@ * 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(); } } diff --git a/system/general/src/test/java/org/wamblee/system/graph/component/ConnectRequiredProvidedEdgeFilterTest.java b/system/general/src/test/java/org/wamblee/system/graph/component/ConnectRequiredProvidedEdgeFilterTest.java index 942eb82b..90c318b0 100644 --- a/system/general/src/test/java/org/wamblee/system/graph/component/ConnectRequiredProvidedEdgeFilterTest.java +++ b/system/general/src/test/java/org/wamblee/system/graph/component/ConnectRequiredProvidedEdgeFilterTest.java @@ -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",