src.samples.java.ex.LEST_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.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.UncheckedIOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
import com.google.common.base.Throwables;
@SuppressWarnings("all")
public class LEST_Sample {
public Date testLest1(String input) {
try {
DateFormat df = new SimpleDateFormat("YYYY");
return df.parse(input);
} catch (ParseException pe) {
throw new IllegalArgumentException(pe.getMessage());
}
}
public Date testLest2(String input) {
try {
DateFormat df = new SimpleDateFormat("YYYY");
return df.parse(input);
} catch (ParseException pe) {
throw new IllegalArgumentException(pe.getMessage(), pe);
}
}
public Date testLestFP1(String input) throws ParseException {
try {
DateFormat df = new SimpleDateFormat("YYYY");
return df.parse(input);
} catch (ParseException pe) {
throw pe;
}
}
public Date testLestFP2(String input) {
try {
DateFormat df = new SimpleDateFormat("YYYY");
return df.parse(input);
} catch (ParseException pe) {
IllegalArgumentException iae = new IllegalArgumentException(pe.getMessage());
iae.initCause(pe);
throw iae;
}
}
public void testLestFP3(String s) {
double d;
try {
d = Double.parseDouble(s);
} catch (NumberFormatException nfe) {
}
throw new RuntimeException("ok");
}
public void testLestFP4(String s) throws Exception {
double d;
try {
d = Double.parseDouble(s);
} catch (NumberFormatException nfe) {
Exception e = wrap(nfe);
throw e;
}
}
public void testLestFP5(String s) throws Exception {
double d;
try {
d = Double.parseDouble(s);
} catch (NumberFormatException nfe) {
Exception e = wrapStatic(nfe);
throw e;
}
}
public void testLestFP6(String s) throws Exception {
double d;
try {
d = Double.parseDouble(s);
} finally {
throw new Exception("Yikes");
}
}
public void testLestFP7(String s) {
try {
double d = Double.parseDouble(s);
} catch (NumberFormatException e) {
throw new RuntimeException(e);
}
}
public void testLestFP8() {
try {
Thread.sleep(10L);
} catch (Exception ex) {
throw new AssertionError(ex);
}
}
public void testLestFP3510540() throws Exception {
boolean bool = true;
if (bool) {
try {
throw new IOException();
} catch (IOException ioe) {
throw new Exception(ioe);
}
} else {
throw new Exception("message");
}
}
public double testAssertFPLest(String input) {
try {
return Double.valueOf(input);
} catch (NumberFormatException e) {
throw new AssertionError(e);
}
}
public void fpThrowables() {
try {
InputStream is = new FileInputStream("foo");
} catch (IOException e) {
throw Throwables.propagate(e);
}
}
public void fpUseCause(Method method, Object target, Object... args) throws Throwable {
try {
method.invoke(target, args);
} catch (InvocationTargetException e) {
throw e.getCause();
}
}
private Exception wrap(Exception e) {
return new Exception(e);
}
private static Exception wrapStatic(Exception e) {
return new Exception(e);
}
public void testFPSuppressedLest(String s) {
try {
double d = Double.parseDouble(s);
} catch (NumberFormatException e) {
RuntimeException r = new RuntimeException();
r.addSuppressed(e);
throw r;
}
}
public void testFPUncheckedIOException290(List s) throws IOException {
try {
List fis = s.stream().map(ss -> {
try {
return new FileInputStream(ss);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}).collect(Collectors.toList());
} catch (UncheckedIOException e) {
throw e.getCause();
}
}
static Class> testFP226(final String clazz) {
if (clazz != null) {
try {
return Class.forName(clazz);
} catch (final ClassNotFoundException e) {
throw new UnsupportedOperationException(e);
}
}
throw new NullPointerException();
}
}