Summary: @public Using InferBuiltins.assume previously caused an assertion failure in the analyzer. Fixed this, and fixed the implementation of the assume builtin to block when the assumed condition cannot hold. Test Plan: Added several new tests.master
parent
695c87377e
commit
f6784e3796
@ -0,0 +1,7 @@
|
||||
prebuilt_jar(
|
||||
name = 'models',
|
||||
binary_jar = 'models.jar',
|
||||
visibility = [
|
||||
'PUBLIC'
|
||||
]
|
||||
)
|
@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright (c) 2013- Facebook.
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
package codetoanalyze.java.infer;
|
||||
|
||||
import com.facebook.infer.models.InferBuiltins;
|
||||
|
||||
public class Builtins {
|
||||
|
||||
void blockError() {
|
||||
Object x = null;
|
||||
InferBuiltins.assume(x != null);
|
||||
x.toString();
|
||||
}
|
||||
|
||||
void doNotBlockError(Object x) {
|
||||
Object y = null;
|
||||
InferBuiltins.assume(x != null);
|
||||
y.toString();
|
||||
}
|
||||
|
||||
void blockErrorIntAssume(Object x) {
|
||||
Object y = null;
|
||||
int i = 0;
|
||||
InferBuiltins.assume(i != 0);
|
||||
y.toString();
|
||||
}
|
||||
|
||||
void causeError(Object x) {
|
||||
InferBuiltins.assume(x == null);
|
||||
x.toString();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (c) 2013- Facebook.
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
package endtoend.java.infer;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static utils.matchers.ResultContainsExactly.containsExactly;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import utils.InferException;
|
||||
import utils.InferResults;
|
||||
|
||||
public class BuiltinsTest {
|
||||
|
||||
public static final String SOURCE_FILE =
|
||||
"infer/tests/codetoanalyze/java/infer/Builtins.java";
|
||||
|
||||
public static final String NULL_DEREFERENCE = "NULL_DEREFERENCE";
|
||||
|
||||
private static InferResults inferResults;
|
||||
|
||||
@BeforeClass
|
||||
public static void loadResults() throws InterruptedException, IOException {
|
||||
inferResults = InferResults.loadInferResults(
|
||||
BuiltinsTest.class,
|
||||
SOURCE_FILE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchErrors()
|
||||
throws IOException, InterruptedException, InferException {
|
||||
String[] methods = {
|
||||
"doNotBlockError",
|
||||
"causeError"
|
||||
};
|
||||
assertThat(
|
||||
"Results should contain " + NULL_DEREFERENCE,
|
||||
inferResults,
|
||||
containsExactly(
|
||||
NULL_DEREFERENCE,
|
||||
SOURCE_FILE,
|
||||
methods
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in new issue