All Downloads are FREE. Search and download functionalities are using the official Maven repository.

src.samples.java.ex.BSB_Sample Maven / Gradle / Ivy

Go to download

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.

There is a newer version: 7.6.8
Show newest version
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);
            }
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy