Skip to content

Commit

Permalink
ClassInfo did not have an equals method and List contains checks woul…
Browse files Browse the repository at this point in the history
…d always return false resulting in duplicate kilim state classes being generated
  • Loading branch information
pellcorp committed Jul 17, 2013
1 parent aca86c5 commit 4652e28
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/kilim/analysis/ClassInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,30 @@ public ClassInfo(String aClassName, byte[] aBytes) {
public String toString() {
return className;
}

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + className.hashCode();
return result;
}

@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (!(obj instanceof ClassInfo)) {
return false;
}
ClassInfo other = (ClassInfo) obj;
if (!className.equals(other.className)) {
return false;
}
return true;
}
}
1 change: 1 addition & 0 deletions test/kilim/test/AllNotWoven.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public static Test suite() {
ret.addTestSuite(TestJSR.class);
ret.addTestSuite(TestFlow.class);
ret.addTestSuite(TestExprs.class);
ret.addTestSuite(TestClassInfo.class);
// ret.addTestSuite(TestInvalidPausables.class);
ret.addTestSuite(TestDynamicWeaver.class);
return ret;
Expand Down
19 changes: 19 additions & 0 deletions test/kilim/test/TestClassInfo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package kilim.test;

import java.util.LinkedList;
import java.util.List;

import junit.framework.TestCase;
import kilim.analysis.ClassInfo;

public class TestClassInfo extends TestCase {
public void testContains() throws Exception {
List<ClassInfo> classInfoList = new LinkedList<ClassInfo>();

ClassInfo classOne = new ClassInfo("kilim/S_01.class", "whocares".getBytes("UTF-8"));
classInfoList.add(classOne);

ClassInfo classTwo = new ClassInfo("kilim/S_01.class", "whocares".getBytes("UTF-8"));
assertTrue(classInfoList.contains(classTwo));
}
}

0 comments on commit 4652e28

Please sign in to comment.