facebook / facebook/infer

Annotation @Test(expected=NullPointerException.class) ignored

Open
#537 6 comments 0 reactions 0 assignees View on GitHub
wishlist
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.