Annotation @Test(expected=NullPointerException.class) ignored
- Dominant language
- OCaml
- Stars
- 15.7k
- Forks
- 2.1k
- Avg merge
- 19h 36m
- Merged PRs (30d)
- 13
Description
Hello Infer Team,
I would consider the below a false-positive, but you might as well tell me that this is by design and `@SuppressWarnings("infer")` should be used instead. Here's an example code:
```
import org.junit.Test;
class NullTest
{
public void convert()
{
}
public void convert(NullTest nt)
{
nt.convert();
}
@Test(expected=NullPointerException.class)
public void should_fail() throws Exception
{
convert(null);
}
}
```
with the result
```
$ infer/bin/infer -- javac -cp /usr/share/java/junit4.jar NullTest.java
[...]
NullTest.java:17: error: NULL_DEREFERENCE
object null could be null and is dereferenced by call to convert(...) at line 17
[...]
```
and infer-out/report.json confirms that the trace originates at `should_fail`:
```
"bug_trace":[{"level":0,"filename":"NullTest.java","line_number":15,"description":"start of procedure should_fail()", ...
```
My claim is that `@Test` with `expected=NullPointerException.class` should possibly only yield a report if there is _no_ null dereference.
Thanks,
Michael
Contributor guide
Assessment
This issue has not been assessed yet.