src.samples.java.ex.BSB_Sample Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of fb-contrib Show documentation
Show all versions of fb-contrib Show documentation
An auxiliary findbugs.sourceforge.net plugin for java bug detectors that fall outside the narrow scope of detectors to be packaged with the product itself.
package ex;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
@SuppressWarnings("all")
public class BSB_Sample {
private Object lock = new Object();
private Set info = new HashSet();
private Map synchMap = Collections.synchronizedMap(new HashMap());
public void testFieldBeginBloated(int i, int j) {
synchronized (lock) {
StringBuffer sb = new StringBuffer();
sb.append("Test");
sb.append(i);
info.add(sb.toString());
}
}
public void testLocalBeginBloated(int j) {
Set i = getInfo();
synchronized (i) {
StringBuffer sb = new StringBuffer();
sb.append("Test");
sb.append(j);
i.add(sb.toString());
}
}
public void testAliasedLocalBeginBloated(int j) {
Set i = getInfo();
synchronized (info) {
StringBuffer sb = new StringBuffer();
sb.append("Test");
sb.append(j);
i.add(sb.toString());
}
}
public void testBranchCutDown(int j) {
Set i = getInfo();
synchronized (i) {
StringBuffer sb = new StringBuffer();
if (sb.length() > 0) {
sb.append("Test");
sb.append(j);
i.add(sb.toString());
}
}
}
public Set getInfo() {
return info;
}
public void accessSyncMap() {
Set keySet = synchMap.keySet();
synchronized (synchMap) {
for (Iterator it = keySet.iterator(); it.hasNext();) {
String key = (String) it.next();
Object obj = synchMap.get(key);
}
}
}
}