Renaming biabduction Java tests

Summary: Renaming biabduction tests in infer/tests/codetoanalyze/java/biabduction/*.java to follow our naming convention: fooOk for tests where no report is expected, fooBad when we expect a report, and FP_ or FN_ prefixes when reality doesn't match the expectation

Reviewed By: jvillard

Differential Revision: D25900575

fbshipit-source-id: ad1370085
master
Gabriela Cunha Sampaio 4 years ago committed by Facebook GitHub Bot
parent 34eb8ebafb
commit caa8bd0e39

@ -13,7 +13,7 @@ public class AnalysisStops {
private native Object externalFunc(); private native Object externalFunc();
public void skipPointerDerefMayCauseLocalFalseNegative() { public void skipPointerDerefMayCauseLocalFalseNegativeBad() {
Object ret = externalFunc(); Object ret = externalFunc();
ret.toString(); ret.toString();
int i = 1 / 0; int i = 1 / 0;
@ -25,7 +25,7 @@ public class AnalysisStops {
return new Object(); return new Object();
} }
public void skipPointerDerefMayCauseCalleeFalsePositive() { public void skipPointerDerefMayCauseCalleeFalsePositiveOk() {
Object o = skipPointerDerefPreventsSpecInferenceRetObj(); Object o = skipPointerDerefPreventsSpecInferenceRetObj();
o.toString(); o.toString();
} }
@ -36,7 +36,7 @@ public class AnalysisStops {
return 0; return 0;
} }
public void skipPointerDerefMayCauseCalleeFalseNegative() { public void skipPointerDerefMayCauseCalleeFalseNegativeBad() {
int ret = skipPointerDerefPreventsSpecInferenceRetZero(); int ret = skipPointerDerefPreventsSpecInferenceRetZero();
int i = 1 / ret; int i = 1 / ret;
} }
@ -45,7 +45,7 @@ public class AnalysisStops {
int j = 1 / i; int j = 1 / i;
} }
public void skipPointerDerefMayCauseInterprocFalseNegative() { public void skipPointerDerefMayCauseInterprocFalseNegativeBad() {
int i = skipPointerDerefPreventsSpecInferenceRetZero(); int i = skipPointerDerefPreventsSpecInferenceRetZero();
divideByParam(i); divideByParam(i);
} }
@ -54,12 +54,12 @@ public class AnalysisStops {
return (String) externalFunc(); return (String) externalFunc();
} }
public void castFailureOnUndefinedObjMayCauseFalseNegative() { public void castFailureOnUndefinedObjMayCauseFalseNegativeBad() {
castExternalPreventsSpecInference(); castExternalPreventsSpecInference();
int i = 1 / 0; int i = 1 / 0;
} }
public void callOnCastUndefinedObjMayCauseFalseNegative() { public void callOnCastUndefinedObjMayCauseFalseNegativeBad() {
String s = castExternalPreventsSpecInference(); String s = castExternalPreventsSpecInference();
s.toString(); s.toString();
int i = 1 / 0; int i = 1 / 0;
@ -81,54 +81,54 @@ public class AnalysisStops {
private native MyObj externalFunc2(); private native MyObj externalFunc2();
public void callOnUndefinedObjMayCauseFalseNegative() { public void callOnUndefinedObjMayCauseFalseNegativeBad() {
MyObj ret = externalFunc2(); MyObj ret = externalFunc2();
int i = 1 / ret.retZero(); int i = 1 / ret.retZero();
} }
public void callOnUndefinedObjMayCauseFalsePositive() { public void callOnUndefinedObjMayCauseFalsePositiveOk() {
MyObj ret = externalFunc2(); MyObj ret = externalFunc2();
int i = 1 / ret.retOne(); int i = 1 / ret.retOne();
} }
public void fieldWriteOnUndefinedObjMayCauseFalseNegative() { public void fieldWriteOnUndefinedObjMayCauseFalseNegativeBad() {
MyObj ret = externalFunc2(); MyObj ret = externalFunc2();
ret.f = new Object(); ret.f = new Object();
int i = 1 / 0; int i = 1 / 0;
} }
public void fieldWriteOnUndefinedObjMayCauseFalsePositive() { public void fieldWriteOnUndefinedObjMayCauseFalsePositiveOk() {
MyObj ret = externalFunc2(); MyObj ret = externalFunc2();
ret.f = new Object(); ret.f = new Object();
ret.f.toString(); ret.f.toString();
} }
public void fieldReadOnUndefinedObjMayCauseFalseNegative() { public void fieldReadOnUndefinedObjMayCauseFalseNegativeBad() {
MyObj ret = externalFunc2(); MyObj ret = externalFunc2();
Object o = ret.f; Object o = ret.f;
int i = 1 / 0; int i = 1 / 0;
} }
public void fieldReadOnUndefinedObjMayCauseFalsePositive() { public void fieldReadOnUndefinedObjMayCauseFalsePositiveOk() {
MyObj ret = externalFunc2(); MyObj ret = externalFunc2();
Object o = ret.f; Object o = ret.f;
o.toString(); o.toString();
} }
public void recursiveAngelicTypesMayCauseFalseNegative() { public void recursiveAngelicTypesMayCauseFalseNegativeBad() {
MyObj ret = externalFunc2(); MyObj ret = externalFunc2();
MyObj rec1 = ret.rec; MyObj rec1 = ret.rec;
MyObj rec2 = rec1.rec; MyObj rec2 = rec1.rec;
int i = 1 / 0; int i = 1 / 0;
} }
public void recursiveAngelicTypesMayCauseFalsePositive() { public void recursiveAngelicTypesMayCauseFalsePositiveOk() {
MyObj ret = externalFunc2(); MyObj ret = externalFunc2();
MyObj rec1 = ret.rec; MyObj rec1 = ret.rec;
rec1.rec.toString(); rec1.rec.toString();
} }
public void infiniteMaterializationMayCauseFalseNegative(boolean b) { public void infiniteMaterializationMayCauseFalseNegativeBad(boolean b) {
MyObj rec = externalFunc2(); MyObj rec = externalFunc2();
while (b) { while (b) {
rec = rec.rec; rec = rec.rec;
@ -136,7 +136,7 @@ public class AnalysisStops {
int i = 1 / 0; int i = 1 / 0;
} }
public void infiniteMaterializationMayCauseFalsePositive(boolean b) { public void infiniteMaterializationMayCauseFalsePositiveOk(boolean b) {
MyObj rec = externalFunc2(); MyObj rec = externalFunc2();
while (b) { while (b) {
rec = rec.rec; rec = rec.rec;
@ -144,7 +144,7 @@ public class AnalysisStops {
rec.toString(); rec.toString();
} }
public void primitiveFieldOfAngelicObjMayCauseFalseNegative() { public void primitiveFieldOfAngelicObjMayCauseFalseNegativeBad() {
MyObj ret = externalFunc2(); MyObj ret = externalFunc2();
if (ret.i == 0) { if (ret.i == 0) {
int i = 1 / 0; int i = 1 / 0;
@ -153,14 +153,14 @@ public class AnalysisStops {
} }
} }
public void primitiveFieldOfAngelicObjMayCauseFalsePositive() { public void primitiveFieldOfAngelicObjMayCauseFalsePositiveOk() {
MyObj ret = externalFunc2(); MyObj ret = externalFunc2();
if (ret.i != 0) { if (ret.i != 0) {
int i = 1 / ret.i; int i = 1 / ret.i;
} }
} }
public void heapFieldOfAngelicObjMayCauseFalseNegative() { public void heapFieldOfAngelicObjMayCauseFalseNegativeBad() {
MyObj ret = externalFunc2(); MyObj ret = externalFunc2();
Object obj = ret.f; Object obj = ret.f;
if (obj == ret.f) { if (obj == ret.f) {
@ -168,7 +168,7 @@ public class AnalysisStops {
} }
} }
public void heapFieldOfAngelicObjMayCauseFalsePositive() { public void heapFieldOfAngelicObjMayCauseFalsePositiveOk() {
MyObj ret = externalFunc2(); MyObj ret = externalFunc2();
Object obj = ret.f; Object obj = ret.f;
if (obj != ret.f) { if (obj != ret.f) {
@ -176,7 +176,7 @@ public class AnalysisStops {
} }
} }
public void fieldReadAferCastMayCauseFalseNegative(Iterator<MyObj> iter) { public void fieldReadAferCastMayCauseFalseNegativeBad(Iterator<MyObj> iter) {
MyObj ret = iter.next(); MyObj ret = iter.next();
Object obj = ret.f; Object obj = ret.f;
obj.toString(); obj.toString();
@ -186,51 +186,51 @@ public class AnalysisStops {
} }
} }
public void derefParam(MyObj obj) { public void derefParamOk(MyObj obj) {
Object f = obj.f; Object f = obj.f;
f.toString(); f.toString();
} }
public void fieldReadInCalleeMayCauseFalsePositive() { public void fieldReadInCalleeMayCauseFalsePositiveOk() {
MyObj ret = externalFunc2(); MyObj ret = externalFunc2();
derefParam(ret); derefParamOk(ret);
} }
public void fieldReadInCalleeMayCauseFalseNegative() { public void fieldReadInCalleeMayCauseFalseNegativeBad() {
MyObj ret = externalFunc2(); MyObj ret = externalFunc2();
ret.f = null; ret.f = null;
derefParam(ret); derefParamOk(ret);
} }
public void fieldReadInCalleeWithAngelicObjFieldMayCauseFalsePositive() { public void fieldReadInCalleeWithAngelicObjFieldMayCauseFalsePositiveOk() {
MyObj ret = externalFunc2(); MyObj ret = externalFunc2();
derefParam(ret.rec); derefParamOk(ret.rec);
} }
public void fieldReadInCalleeWithAngelicObjFieldMayCauseFalseNegative() { public void fieldReadInCalleeWithAngelicObjFieldMayCauseFalseNegativeBad() {
MyObj ret = externalFunc2(); MyObj ret = externalFunc2();
ret.rec.f = null; ret.rec.f = null;
derefParam(ret.rec); derefParamOk(ret.rec);
} }
public void accessPathOnParam(MyObj obj) { public void accessPathOnParamOk(MyObj obj) {
MyObj ret = obj.rec; MyObj ret = obj.rec;
Object f = ret.f; Object f = ret.f;
f.toString(); f.toString();
} }
public void accessPathInCalleeMayCauseFalsePositive() { public void accessPathInCalleeMayCauseFalsePositiveOk() {
MyObj ret = externalFunc2(); MyObj ret = externalFunc2();
accessPathOnParam(ret); accessPathOnParamOk(ret);
} }
public void accessPathInCalleeMayCauseFalseNegative() { public void accessPathInCalleeMayCauseFalseNegativeBad() {
MyObj ret = externalFunc2(); MyObj ret = externalFunc2();
ret.rec.f = null; ret.rec.f = null;
accessPathOnParam(ret); accessPathOnParamOk(ret);
} }
public void skipFunctionInLoopMayCauseFalseNegative() { public void skipFunctionInLoopMayCauseFalseNegativeBad() {
Object o = null; Object o = null;
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
externalFunc(); externalFunc();
@ -239,32 +239,32 @@ public class AnalysisStops {
} }
// will fail to find error unless spec inference succeeds for all callees // will fail to find error unless spec inference succeeds for all callees
public void specInferenceMayFailAndCauseFalseNegative(boolean b, Iterator<MyObj> iter) { public void specInferenceMayFailAndCauseFalseNegativeBad(boolean b, Iterator<MyObj> iter) {
skipPointerDerefMayCauseLocalFalseNegative(); skipPointerDerefMayCauseLocalFalseNegativeBad();
skipPointerDerefPreventsSpecInferenceRetObj(); skipPointerDerefPreventsSpecInferenceRetObj();
skipPointerDerefPreventsSpecInferenceRetZero(); skipPointerDerefPreventsSpecInferenceRetZero();
skipPointerDerefMayCauseCalleeFalseNegative(); skipPointerDerefMayCauseCalleeFalseNegativeBad();
skipPointerDerefMayCauseInterprocFalseNegative(); skipPointerDerefMayCauseInterprocFalseNegativeBad();
castFailureOnUndefinedObjMayCauseFalseNegative(); castFailureOnUndefinedObjMayCauseFalseNegativeBad();
callOnCastUndefinedObjMayCauseFalseNegative(); callOnCastUndefinedObjMayCauseFalseNegativeBad();
callOnUndefinedObjMayCauseFalseNegative(); callOnUndefinedObjMayCauseFalseNegativeBad();
callOnUndefinedObjMayCauseFalsePositive(); callOnUndefinedObjMayCauseFalsePositiveOk();
fieldWriteOnUndefinedObjMayCauseFalseNegative(); fieldWriteOnUndefinedObjMayCauseFalseNegativeBad();
fieldWriteOnUndefinedObjMayCauseFalsePositive(); fieldWriteOnUndefinedObjMayCauseFalsePositiveOk();
fieldReadOnUndefinedObjMayCauseFalseNegative(); fieldReadOnUndefinedObjMayCauseFalseNegativeBad();
fieldReadOnUndefinedObjMayCauseFalsePositive(); fieldReadOnUndefinedObjMayCauseFalsePositiveOk();
recursiveAngelicTypesMayCauseFalseNegative(); recursiveAngelicTypesMayCauseFalseNegativeBad();
recursiveAngelicTypesMayCauseFalsePositive(); recursiveAngelicTypesMayCauseFalsePositiveOk();
infiniteMaterializationMayCauseFalseNegative(b); infiniteMaterializationMayCauseFalseNegativeBad(b);
infiniteMaterializationMayCauseFalsePositive(b); infiniteMaterializationMayCauseFalsePositiveOk(b);
primitiveFieldOfAngelicObjMayCauseFalsePositive(); primitiveFieldOfAngelicObjMayCauseFalsePositiveOk();
primitiveFieldOfAngelicObjMayCauseFalseNegative(); primitiveFieldOfAngelicObjMayCauseFalseNegativeBad();
heapFieldOfAngelicObjMayCauseFalsePositive(); heapFieldOfAngelicObjMayCauseFalsePositiveOk();
heapFieldOfAngelicObjMayCauseFalseNegative(); heapFieldOfAngelicObjMayCauseFalseNegativeBad();
fieldReadAferCastMayCauseFalseNegative(iter); fieldReadAferCastMayCauseFalseNegativeBad(iter);
fieldReadInCalleeMayCauseFalsePositive(); fieldReadInCalleeMayCauseFalsePositiveOk();
fieldReadInCalleeWithAngelicObjFieldMayCauseFalsePositive(); fieldReadInCalleeWithAngelicObjFieldMayCauseFalsePositiveOk();
accessPathInCalleeMayCauseFalsePositive(); accessPathInCalleeMayCauseFalsePositiveOk();
int i = 1 / 0; int i = 1 / 0;
} }
} }

@ -9,40 +9,40 @@ package codetoanalyze.java.infer;
public class ArrayOutOfBounds { public class ArrayOutOfBounds {
public int arrayOutOfBounds() { public int arrayOutOfBoundsBad() {
int[] arr = new int[1]; int[] arr = new int[1];
return arr[3]; return arr[3];
} }
public int arrayInBounds() { public int arrayInBoundsOk() {
int[] arr = new int[2]; int[] arr = new int[2];
return arr[1]; return arr[1];
} }
// tests below this line are turned off until array functionality improves // tests below this line are turned off until array functionality improves
public void arrayLoopOutOfBounds(int[] arr) { public void FN_arrayLoopOutOfBoundsBad(int[] arr) {
for (int i = 0; i <= arr.length; i++) { for (int i = 0; i <= arr.length; i++) {
int j = arr[i]; int j = arr[i];
} }
} }
public void arrayLoopInBounds(int[] arr) { public void arrayLoopInBoundsOk(int[] arr) {
for (int i = 0; i < arr.length; i++) { for (int i = 0; i < arr.length; i++) {
int j = arr[i]; int j = arr[i];
} }
} }
public void buggyIter(int[] arr1, int[] arr2) { public void FN_buggyIterBad(int[] arr1, int[] arr2) {
for (int i = 0; i < arr1.length; i++) { for (int i = 0; i < arr1.length; i++) {
arr2[i] = 7; arr2[i] = 7;
} }
} }
public void switchedArrsOutOfBounds() { public void FN_switchedArrsOutOfBoundsBad() {
buggyIter(new int[11], new int[10]); FN_buggyIterBad(new int[11], new int[10]);
} }
public void buggyNestedLoop1(int[] arr1, int[] arr2) { public void FN_buggyNestedLoop1Bad(int[] arr1, int[] arr2) {
for (int i = 0; i < arr1.length; i++) { for (int i = 0; i < arr1.length; i++) {
for (int j = 0; i < arr2.length; j++) { for (int j = 0; i < arr2.length; j++) {
arr1[i] = arr1[i] + arr2[j]; arr1[i] = arr1[i] + arr2[j];
@ -50,11 +50,11 @@ public class ArrayOutOfBounds {
} }
} }
public void nestedOutOfBounds1() { public void FN_nestedOutOfBounds1Bad() {
buggyNestedLoop1(new int[11], new int[10]); FN_buggyNestedLoop1Bad(new int[11], new int[10]);
} }
public void buggyNestedLoop2(int[] arr1, int[] arr2) { public void FN_buggyNestedLoop2Bad(int[] arr1, int[] arr2) {
for (int i = 0; i < arr1.length; i++) { for (int i = 0; i < arr1.length; i++) {
for (int j = 0; j < arr2.length; i++) { for (int j = 0; j < arr2.length; i++) {
arr1[i] = arr1[i] + arr2[j]; arr1[i] = arr1[i] + arr2[j];
@ -62,11 +62,11 @@ public class ArrayOutOfBounds {
} }
} }
public void nestedOutOfBounds2() { public void FN_nestedOutOfBounds2Bad() {
buggyNestedLoop2(new int[11], new int[10]); FN_buggyNestedLoop2Bad(new int[11], new int[10]);
} }
public void buggyNestedLoop3(int[] arr1, int[] arr2) { public void FN_buggyNestedLoop3Bad(int[] arr1, int[] arr2) {
for (int i = 0; i < arr1.length; i++) { for (int i = 0; i < arr1.length; i++) {
for (int j = 0; j < arr2.length; j++) { for (int j = 0; j < arr2.length; j++) {
arr1[i] = 2 * arr2[i]; arr1[i] = 2 * arr2[i];
@ -74,11 +74,11 @@ public class ArrayOutOfBounds {
} }
} }
public void nestedOutOfBounds3() { public void FN_nestedOutOfBounds3Bad() {
buggyNestedLoop3(new int[11], new int[10]); FN_buggyNestedLoop3Bad(new int[11], new int[10]);
} }
public void safeNestedLoop(int[] arr1, int[] arr2) { public void safeNestedLoopOk(int[] arr1, int[] arr2) {
for (int i = 0; i < arr1.length; i++) { for (int i = 0; i < arr1.length; i++) {
for (int j = 0; j < arr2.length; j++) { for (int j = 0; j < arr2.length; j++) {
arr1[i] = arr1[i] + arr2[j]; arr1[i] = arr1[i] + arr2[j];
@ -86,7 +86,7 @@ public class ArrayOutOfBounds {
} }
} }
public void nestedInBounds() { public void nestedInBoundsOk() {
safeNestedLoop(new int[11], new int[10]); safeNestedLoopOk(new int[11], new int[10]);
} }
} }

@ -11,7 +11,7 @@ package codetoanalyze.java.infer;
public class AutoGenerated { public class AutoGenerated {
void npe() { void npeBad() {
String s = null; String s = null;
int n = s.length(); int n = s.length();
} }

@ -11,26 +11,26 @@ import com.facebook.infer.builtins.InferBuiltins;
public class Builtins { public class Builtins {
void blockError() { void blockErrorOk() {
Object x = null; Object x = null;
InferBuiltins.assume(x != null); InferBuiltins.assume(x != null);
x.toString(); x.toString();
} }
void doNotBlockError(Object x) { void doNotBlockErrorBad(Object x) {
Object y = null; Object y = null;
InferBuiltins.assume(x != null); InferBuiltins.assume(x != null);
y.toString(); y.toString();
} }
void blockErrorIntAssume(Object x) { void blockErrorIntAssumeOk(Object x) {
Object y = null; Object y = null;
int i = 0; int i = 0;
InferBuiltins.assume(i != 0); InferBuiltins.assume(i != 0);
y.toString(); y.toString();
} }
void causeError(Object x) { void causeErrorBad(Object x) {
InferBuiltins.assume(x == null); InferBuiltins.assume(x == null);
x.toString(); x.toString();
} }

@ -36,31 +36,31 @@ class AnotherImplementationOfInterface implements MyInterface {
public class ClassCastExceptions { public class ClassCastExceptions {
public void classCastException() { public void classCastExceptionBad() {
SuperClass a = new SubClassA(); SuperClass a = new SubClassA();
SubClassB b = (SubClassB) a; SubClassB b = (SubClassB) a;
} }
public int classCastExceptionImplementsInterfaceCallee(MyInterface i) { public int classCastExceptionImplementsInterfaceCalleeOk(MyInterface i) {
ImplementationOfInterface impl = (ImplementationOfInterface) i; ImplementationOfInterface impl = (ImplementationOfInterface) i;
return impl.getInt(); return impl.getInt();
} }
public int classCastExceptionImplementsInterface() { public int classCastExceptionImplementsInterfaceBad() {
return classCastExceptionImplementsInterfaceCallee(new AnotherImplementationOfInterface()); return classCastExceptionImplementsInterfaceCalleeOk(new AnotherImplementationOfInterface());
} }
public String getURL() { public String getURL() {
return "http://bla.com"; return "http://bla.com";
} }
public void openHttpURLConnection() throws IOException { public void openHttpURLConnectionOk() throws IOException {
URL url = new URL(getURL()); URL url = new URL(getURL());
HttpURLConnection connection = (HttpURLConnection) url.openConnection(); HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.disconnect(); connection.disconnect();
} }
public void castingArrayOfPrimitiveTypeOK(int[] a) { public void castingArrayOfPrimitiveTypeOk(int[] a) {
int[] b = (int[]) a; int[] b = (int[]) a;
} }
} }

@ -100,28 +100,28 @@ public class CloseableAsResourceExample {
} }
} }
void withException() throws LocalException { void withExceptionBad() throws LocalException {
SomeResource res = new SomeResource(); SomeResource res = new SomeResource();
res.doSomething(); res.doSomething();
res.close(); res.close();
} // should report a resource leak } // should report a resource leak
void closingWrapper() { void closingWrapperOk() {
Resource r = new Resource(); Resource r = new Resource();
Sub s = new Sub(r); Sub s = new Sub(r);
s.close(); s.close();
} }
void notClosingWrapper() { void notClosingWrapperBad() {
Sub s = new Sub(new Resource()); Sub s = new Sub(new Resource());
s.mR.close(); s.mR.close();
} // should report a resource leak } // should report a resource leak
void noNeedToCloseStringReader() { void noNeedToCloseStringReaderOk() {
StringReader stringReader = new StringReader("paf!"); StringReader stringReader = new StringReader("paf!");
} }
void noNeedToCloseByteArrayOutputStream() { void noNeedToCloseByteArrayOutputStreamOk() {
ByteArrayOutputStream stream = new ByteArrayOutputStream(42); ByteArrayOutputStream stream = new ByteArrayOutputStream(42);
} }
@ -130,11 +130,11 @@ public class CloseableAsResourceExample {
ByteArrayInputStreamWrapper stream2 = new ByteArrayInputStreamWrapper(array); ByteArrayInputStreamWrapper stream2 = new ByteArrayInputStreamWrapper(array);
} }
void noNeedToCloseByteArrayInputStream(byte[] array) { void noNeedToCloseByteArrayInputStreamOk(byte[] array) {
ByteArrayInputStream stream = new ByteArrayInputStream(array); ByteArrayInputStream stream = new ByteArrayInputStream(array);
} }
void closingWithCloseQuietly() { void closingWithCloseQuietlyOk() {
SomeResource r = null; SomeResource r = null;
try { try {
r = new SomeResource(); r = new SomeResource();
@ -145,7 +145,7 @@ public class CloseableAsResourceExample {
} }
} }
void failToCloseWithCloseQuietly() { void failToCloseWithCloseQuietlyBad() {
try { try {
SomeResource r = new SomeResource(); SomeResource r = new SomeResource();
r.doSomething(); r.doSomething();
@ -154,17 +154,17 @@ public class CloseableAsResourceExample {
} }
} }
void noLeakwithExceptionOnClose() throws IOException { void noLeakwithExceptionOnCloseOk() throws IOException {
ResourceWithException res = new ResourceWithException(); ResourceWithException res = new ResourceWithException();
res.close(); res.close();
} }
void noLeakWithCloseQuietlyAndExceptionOnClose() { void noLeakWithCloseQuietlyAndExceptionOnCloseOk() {
ResourceWithException res = new ResourceWithException(); ResourceWithException res = new ResourceWithException();
Utils.closeQuietly(res); Utils.closeQuietly(res);
} }
static T sourceOfNullWithResourceLeak() { static T sourceOfNullWithResourceLeakBad() {
SomeResource r = new SomeResource(); SomeResource r = new SomeResource();
return null; return null;
} }
@ -175,16 +175,16 @@ public class CloseableAsResourceExample {
public void close() {} public void close() {}
} }
void leakFoundWhenIndirectlyImplementingCloseable() { void leakFoundWhenIndirectlyImplementingCloseableBad() {
MyResource res = new MyResource(); MyResource res = new MyResource();
} }
void skippedCallClosesResourceOnArgs() { void skippedCallClosesResourceOnArgsOk() {
SomeResource res = new SomeResource(); SomeResource res = new SomeResource();
SomeResource.bar(res); SomeResource.bar(res);
} }
void skippedVritualCallDoesNotCloseResourceOnReceiver() { void skippedVirtualCallDoesNotCloseResourceOnReceiverOk() {
SomeResource res = new SomeResource(); SomeResource res = new SomeResource();
res.foo(42); res.foo(42);
} }

@ -29,7 +29,7 @@ public class CursorLeaks {
} }
} }
public Object cursorClosedCheckNull(SQLiteDatabase sqLiteDatabase) { public Object cursorClosedCheckNullOk(SQLiteDatabase sqLiteDatabase) {
Cursor cursor = sqLiteDatabase.query("events", null, null, null, null, null, null); Cursor cursor = sqLiteDatabase.query("events", null, null, null, null, null, null);
Object value = null; Object value = null;
@ -47,7 +47,7 @@ public class CursorLeaks {
return value; return value;
} }
public Object cursorClosedCheckNullCheckClosed_FP(SQLiteDatabase sqLiteDatabase) { public Object FP_cursorClosedCheckNullCheckClosedOk(SQLiteDatabase sqLiteDatabase) {
Cursor cursor = sqLiteDatabase.query("events", null, null, null, null, null, null); Cursor cursor = sqLiteDatabase.query("events", null, null, null, null, null, null);
Object value = null; Object value = null;
@ -65,7 +65,7 @@ public class CursorLeaks {
return value; return value;
} }
public int cursorNotClosed(SQLiteDatabase sqLiteDatabase) { public int cursorNotClosedBad(SQLiteDatabase sqLiteDatabase) {
Cursor cursor = sqLiteDatabase.query("events", null, null, null, null, null, null); Cursor cursor = sqLiteDatabase.query("events", null, null, null, null, null, null);
return cursor.getCount(); return cursor.getCount();
} }
@ -73,7 +73,7 @@ public class CursorLeaks {
Context mContext; Context mContext;
ContentResolver mContentResolver; ContentResolver mContentResolver;
public int getImageCountHelperNotClosed(String customClause) { public int getImageCountHelperNotClosedBad(String customClause) {
String[] projection = {"COUNT(*)"}; String[] projection = {"COUNT(*)"};
String selectionClause = selectionClause = customClause; String selectionClause = selectionClause = customClause;
@ -90,7 +90,7 @@ public class CursorLeaks {
} }
} }
public int getImageCountHelperClosed(String customClause) { public int getImageCountHelperClosedOk(String customClause) {
String[] projection = {"COUNT(*)"}; String[] projection = {"COUNT(*)"};
String selectionClause = selectionClause = customClause; String selectionClause = selectionClause = customClause;
@ -107,7 +107,7 @@ public class CursorLeaks {
} }
} }
public int getBucketCountNotClosed() { public int getBucketCountNotClosedBad() {
Cursor cursor = MediaStore.Images.Media.query(mContentResolver, null, null, null, null, null); Cursor cursor = MediaStore.Images.Media.query(mContentResolver, null, null, null, null, null);
if (cursor == null) { if (cursor == null) {
return 0; return 0;
@ -120,7 +120,7 @@ public class CursorLeaks {
} }
} }
public int getBucketCountClosed() { public int getBucketCountClosedOk() {
Cursor cursor = MediaStore.Images.Media.query(mContentResolver, null, null, null, null, null); Cursor cursor = MediaStore.Images.Media.query(mContentResolver, null, null, null, null, null);
if (cursor == null) { if (cursor == null) {
return 0; return 0;
@ -137,21 +137,21 @@ public class CursorLeaks {
} }
} }
private void queryUVMLegacyDbNotClosed() { private void queryUVMLegacyDbNotClosedBad() {
SQLiteQueryBuilder builder = new SQLiteQueryBuilder(); SQLiteQueryBuilder builder = new SQLiteQueryBuilder();
builder.setTables(""); builder.setTables("");
Cursor cursor = builder.query(null, null, "", null, null, null, null); Cursor cursor = builder.query(null, null, "", null, null, null, null);
if (cursor != null) cursor.moveToFirst(); if (cursor != null) cursor.moveToFirst();
} }
private void queryUVMLegacyDbClosed() { private void queryUVMLegacyDbClosedOk() {
SQLiteQueryBuilder builder = new SQLiteQueryBuilder(); SQLiteQueryBuilder builder = new SQLiteQueryBuilder();
builder.setTables(""); builder.setTables("");
Cursor cursor = builder.query(null, null, "", null, null, null, null); Cursor cursor = builder.query(null, null, "", null, null, null, null);
if (cursor != null) cursor.close(); if (cursor != null) cursor.close();
} }
public int completeDownloadClosed(DownloadManager downloadManager) { public int completeDownloadClosedOk(DownloadManager downloadManager) {
DownloadManager.Query query = new DownloadManager.Query(); DownloadManager.Query query = new DownloadManager.Query();
Cursor cursor = (Cursor) null; Cursor cursor = (Cursor) null;
try { try {
@ -166,7 +166,7 @@ public class CursorLeaks {
} }
} }
public int completeDownloadNotClosed(DownloadManager downloadManager) { public int completeDownloadNotClosedBad(DownloadManager downloadManager) {
DownloadManager.Query query = new DownloadManager.Query(); DownloadManager.Query query = new DownloadManager.Query();
Cursor cursor = null; Cursor cursor = null;
try { try {
@ -181,7 +181,7 @@ public class CursorLeaks {
} }
} }
private void loadPrefsFromContentProviderClosed() { private void loadPrefsFromContentProviderClosedOk() {
ContentProviderClient contentProviderClient = mContentResolver.acquireContentProviderClient(""); ContentProviderClient contentProviderClient = mContentResolver.acquireContentProviderClient("");
if (contentProviderClient != null) { if (contentProviderClient != null) {
Cursor cursor = null; Cursor cursor = null;
@ -198,7 +198,7 @@ public class CursorLeaks {
} }
} }
private void loadPrefsFromContentProviderNotClosed() { private void loadPrefsFromContentProviderNotClosedBad() {
ContentProviderClient contentProviderClient = mContentResolver.acquireContentProviderClient(""); ContentProviderClient contentProviderClient = mContentResolver.acquireContentProviderClient("");
if (contentProviderClient == null) return; if (contentProviderClient == null) return;
Cursor cursor = null; Cursor cursor = null;
@ -223,7 +223,7 @@ public class CursorLeaks {
} }
} }
public Cursor cursorWrapperReturned(SQLiteDatabase sqLiteDatabase) { public Cursor cursorWrapperReturnedOk(SQLiteDatabase sqLiteDatabase) {
Cursor cursor = sqLiteDatabase.query("events", null, null, null, null, null, null); Cursor cursor = sqLiteDatabase.query("events", null, null, null, null, null, null);
return new NamedCursor(cursor, "abc"); return new NamedCursor(cursor, "abc");
} }
@ -237,7 +237,7 @@ public class CursorLeaks {
native NamedCursor createWrapper(Cursor cursor); native NamedCursor createWrapper(Cursor cursor);
public NamedCursor cursorAttachedTheWrapper(SQLiteDatabase sqLiteDatabase) { public NamedCursor cursorAttachedTheWrapperOk(SQLiteDatabase sqLiteDatabase) {
Cursor cursor = sqLiteDatabase.query("events", null, null, null, null, null, null); Cursor cursor = sqLiteDatabase.query("events", null, null, null, null, null, null);
return createWrapper(cursor); return createWrapper(cursor);
} }

@ -31,7 +31,7 @@ public class CursorNPEs {
Context mContext; Context mContext;
ContentResolver mContentResolver; ContentResolver mContentResolver;
public void cursorFromContentResolverNPE(String customClause) { public void cursorFromContentResolverNPEBad(String customClause) {
String[] projection = {"COUNT(*)"}; String[] projection = {"COUNT(*)"};
String selectionClause = selectionClause = customClause; String selectionClause = selectionClause = customClause;
@ -42,7 +42,7 @@ public class CursorNPEs {
cursor.close(); cursor.close();
} }
public void cursorFromMediaNPE() { public void cursorFromMediaNPEBad() {
Cursor cursor = MediaStore.Images.Media.query(mContentResolver, null, null, null, null, null); Cursor cursor = MediaStore.Images.Media.query(mContentResolver, null, null, null, null, null);
cursor.close(); cursor.close();
} }
@ -54,7 +54,7 @@ public class CursorNPEs {
cursor.close(); cursor.close();
} }
public int cursorFromDownloadManagerNPE(DownloadManager downloadManager) { public int cursorFromDownloadManagerNPEBad(DownloadManager downloadManager) {
DownloadManager.Query query = new DownloadManager.Query(); DownloadManager.Query query = new DownloadManager.Query();
Cursor cursor = null; Cursor cursor = null;
try { try {

@ -68,7 +68,7 @@ public class DynamicDispatch {
o.bar().toString(); o.bar().toString();
} }
static void dynamicDispatchShouldNotReportWhenCallingSupertype(Supertype o) { static void FP_dynamicDispatchShouldNotReportWhenCallingSupertype(Supertype o) {
// should not report a warning because the Supertype implementation // should not report a warning because the Supertype implementation
// of foo() does not return null // of foo() does not return null
o.foo().toString(); o.foo().toString();
@ -77,7 +77,7 @@ public class DynamicDispatch {
static void dynamicDispatchShouldReportWhenCalledWithSubtypeParameter(Subtype o) { static void dynamicDispatchShouldReportWhenCalledWithSubtypeParameter(Subtype o) {
// should report a warning because the Subtype implementation // should report a warning because the Subtype implementation
// of foo() returns null // of foo() returns null
dynamicDispatchShouldNotReportWhenCallingSupertype(o); FP_dynamicDispatchShouldNotReportWhenCallingSupertype(o);
} }
static Object dynamicDispatchWrapperFoo(Supertype o) { static Object dynamicDispatchWrapperFoo(Supertype o) {
@ -120,7 +120,7 @@ public class DynamicDispatch {
mField = t; mField = t;
} }
static void dispatchOnFieldGood() { static void dispatchOnFieldOk() {
Supertype subtype = new Subtype(); Supertype subtype = new Subtype();
WithField object = new WithField(subtype); WithField object = new WithField(subtype);
object.mField.bar().toString(); object.mField.bar().toString();

@ -33,7 +33,7 @@ public class IntegerExample {
} }
} }
private static void testIntegerEqualsFN() { private static void testIntegerEqualsOk() {
Integer a = new Integer(42); Integer a = new Integer(42);
Integer b = new Integer(42); Integer b = new Integer(42);
Integer c = null; Integer c = null;

@ -325,7 +325,7 @@ public class NullPointerExceptions {
} }
void someNPEAfterResourceLeak() { void someNPEAfterResourceLeak() {
T t = CloseableAsResourceExample.sourceOfNullWithResourceLeak(); T t = CloseableAsResourceExample.sourceOfNullWithResourceLeakBad();
t.f(); t.f();
} }

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save