Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

False negative with NPE #507

Open
carlonzo opened this issue Nov 20, 2016 · 5 comments
Open

False negative with NPE #507

carlonzo opened this issue Nov 20, 2016 · 5 comments

Comments

@carlonzo
Copy link

Hi all,

I received a NPE on my app. analysing the code it look like it was a very stupid piece of code I wrote. I was interesting in knowing why Infer did not notice it for me even if it looked like an obvious NPE. here is a simplified example that Infer 0.9.4 is not able to detect. my question may be related to this one #500 but I'll leave that to you (infer -a eradicate detects it).

here is the code. funny part is that the NPE is detected if I remove the if statements, which anyway should not change anything. Thanks!

class Infer {
	public Infer(){
		test1(null);
		test2(null);
	}

	void test1(String text) {
		if (text == null){
			text.length();
		}
	}

	void test2(String text) {
		if (text == null){
		}
		text.length();
	}
}
@carlonzo
Copy link
Author

@martinoluca here is the NPE I was mentioning to you at the droidcon

@cristianoc
Copy link
Contributor

Infer filters out NPEs based on a heuristic.
There's a debugging option --no-filtering to turn off the heuristic.

@carlonzo
Copy link
Author

ok thanks. but why if I add the if block, the NPE is filtered? if I remove it (leaving the text.length()) the NPE is non filtered and shows the issues.

@cristianoc
Copy link
Contributor

With the if the report is on test1 and test2, while without the if the report is on the caller: the constructor Infer(). The heuristics tend not to report NPEs when the blame is on the parameter of the function.

@carlonzo
Copy link
Author

carlonzo commented Nov 23, 2016

thanks for your answers even still do not understand why on test2 the if statement is filtering the report. I get that the report is on test2 but I would have expected Infer to assume that the value could be null at that point. even more in test1, as at that point we assert that in that block the value is null. anyway thanks for your time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants