
src.samples.java.ex.BAS_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.
The newest version!
package ex;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.Future;
@SuppressWarnings("all")
public class BAS_Sample {
private final Map m = new HashMap<>();
private long value = 0;
private Long stash = Long.valueOf(0);
public void testIfScope(String s) {
Object o = new Object();
if (s.equals("Foo")) {
s = o.toString();
}
}
public String testFPForScope(String s) {
Object o = new Object();
while (s.length() > 0) {
o = s.substring(0, 1);
s = s.substring(1);
}
return s;
}
public String testFP2Scopes(String s) {
Object o = new Object();
if (s.equals("Boo")) {
s = o.toString();
} else if (s.equals("Hoo")) {
s = o.toString();
}
return s;
}
public String test2InnerScopes(String s) {
Object o = new Object();
if (s != null) {
if (s.equals("Boo")) {
s = o.toString();
} else if (s.equals("Hoo")) {
s = o.toString();
}
}
return s;
}
public String testFPLoopCond(List in) {
StringBuilder sb = new StringBuilder();
for (String s : in) {
sb.append(s);
}
return sb.toString();
}
public List getList() {
return null;
}
public String testSwitch(int a) {
String v = "Test";
switch (a) {
case 1:
v = "Testa";
break;
case 2:
v = "Tesseract";
break;
case 3:
v = "Testy";
break;
default:
v = "Rossa";
break;
}
return null;
}
public void testFPSync(Set a, Set b) {
String c, d;
synchronized (this) {
c = a.iterator().next();
d = b.iterator().next();
}
if (d.length() > 0) {
d = c;
}
}
public int testFPObjChange(Calendar c, boolean b) {
int hour = c.get(Calendar.HOUR_OF_DAY);
c.set(2000, Calendar.JANUARY, 1);
if (b) {
return hour;
}
return 0;
}
public void tstFPThisRefChange(long v, boolean b) {
long oldValue = this.value;
this.value = v;
if (b) {
if (oldValue < 0) {
System.out.println("Negative");
}
}
}
public void tstFPRefChange(Holder h1, Holder h2, boolean b) {
int h = h1.member;
h1 = h2;
if (b) {
System.out.println(h);
}
}
public void tstFPRefChangeThruMethodChain(Holder h1, Holder h2, boolean b) {
String h = h1.toString().trim();
h1 = h2;
if (b) {
System.out.println(h);
}
}
public Long testFPRefNull(boolean b) {
Long save = stash;
stash = null;
if (b) {
return save;
}
return null;
}
public void testFPSrcOverwrite(int src, boolean b) {
int d = src;
src = 0;
if (b) {
System.out.println(d);
}
}
public void testFPRiskies1(boolean b) {
long start = System.currentTimeMillis();
if (b) {
long delta = System.currentTimeMillis() - start;
System.out.println(delta);
}
}
public String testFPIteratorNext(Collection c, boolean b) {
Iterator it = c.iterator();
String s = it.next();
if (b) {
if (s == null) {
return "yay";
}
}
return it.next();
}
public List testFPSynchronized(String s, String p) {
List l = new ArrayList<>();
String x = s;
synchronized (s) {
if (p != null) {
l.add(p);
return l;
}
}
return null;
}
public void testFPNestedIfs(Map x, int i, boolean b) {
String s = x.get("hello");
if (i == 0) {
if (b) {
System.out.println(s);
}
} else if (i == 1) {
System.out.println(s);
} else if (i == 2) {
System.out.println(s);
}
}
public boolean testFPFuture(boolean b) {
ExecutorService s = new ForkJoinPool();
Future f = s.submit(new Runnable() {
@Override
public void run() {
}
});
if (b) {
if (f.isDone()) {
return true;
}
}
return false;
}
public int testFPTwoCatches(List x) throws Exception {
String msg = "This is a test";
try {
return x.size() * x.get(0);
} catch (NullPointerException e) {
throw new Exception(msg + "NPE", e);
} catch (IndexOutOfBoundsException e) {
throw new Exception(msg + "IIOBE", e);
}
}
static class Holder {
int member;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy