Skip to content

Commit

Permalink
add Bug1387
Browse files Browse the repository at this point in the history
  • Loading branch information
billpugh committed Jul 20, 2015
1 parent c41242f commit fd7ec8b
Showing 1 changed file with 70 additions and 0 deletions.
70 changes: 70 additions & 0 deletions findbugsTestCases/src/java/sfBugsNew/Bug1387.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package sfBugsNew;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

public class Bug1387 {

static class PoJo {
final String s;

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((s == null) ? 0 : s.hashCode());
return result;
}

@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
PoJo other = (PoJo) obj;
if (s == null) {
if (other.s != null)
return false;
} else if (!s.equals(other.s))
return false;
return true;
}

public PoJo(String s) {
super();
this.s = s;
}

}
public static void test3() {
Set<String>[] sets = new Set[10];
for (int i = 0; i < 10; ++i) {
sets[i] = Collections.newSetFromMap(new ConcurrentHashMap<String,Boolean>());
sets[i].add("Foo");
}
PoJo p = new PoJo("Foo");
sets[5].remove(p); // <- bug
}

public static void test() {
Set<String> s = Collections.newSetFromMap(new ConcurrentHashMap<String,Boolean>());
s.add("Foo");
PoJo p = new PoJo("Foo");
s.remove(p); // <- bug
}
public static void test2() {
List<Set<String>> sets = new ArrayList<Set<String>>();
for (int i = 0; i < 10; ++i) {
sets.add( Collections.newSetFromMap(new ConcurrentHashMap<String,Boolean>()));
sets.get(i).add("Foo");
}
PoJo p = new PoJo("Foo");
sets.get(5).remove(p); // <- bug
}
}

0 comments on commit fd7ec8b

Please sign in to comment.