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

src.samples.java.ex.LSYC_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.

The newest version!
package ex;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Vector;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class LSYC_Sample {
    List syncfield;

    public Object[] test1(String[] s) {
        Vector v = new Vector();
        v.addAll(Arrays.asList(s));
        Collections.sort(v);
        return v.toArray();
    }

    public void test2(Set s) {
        Set ss = Collections.synchronizedSet(s);
        for (String st : ss) {
            System.out.println(st);
        }
    }

    public String testNotStoredSB() {
        final StringBuffer stringBuffer = new StringBuffer().append("agrego ").append("un ");
        stringBuffer.append("string ");
        return stringBuffer.toString();
    }

    public void test3(List ls) {
        // don't report
        List a = Collections.synchronizedList(ls);
        syncfield = a;

        System.out.println(syncfield);
    }

    public List getList() {
        // don't report
        return Collections.synchronizedList(new ArrayList());

    }

    public Map> test4() {
        // report as low
        Map> main = new Hashtable>();

        Map m = new Hashtable();
        m.put("Hello", "there");
        main.put("First", m);

        return main;
    }

    public String printString() {
        StringBuffer buffer = new StringBuffer();
        for (int i = 0; i < 50; i++)
            buffer.append("Findbugs ");
        return buffer.toString();
    }

    public String printString2() {
        // no tag, but probably should.
        return new StringBuffer().append("Hello").append("World").toString();
    }

    public void testSBReallyRequred(Pattern p, String s, String repl) {
        Matcher matcher = p.matcher(s);
        StringBuffer stringBuffer = new StringBuffer();
        while (matcher.find()) {
            matcher.appendReplacement(stringBuffer, repl);
        }
        matcher.appendTail(stringBuffer);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy