No, you should not ignore it. Because if the assumption is not fulfilled (for example, if findViewById(R.id.toolbar) starts to return null , because you are entering an error in another file in your project), you do want the NullPointerException to be thrown, so you can easily find the error when testing.
In other words: in my opinion, the best approach is unstable fast .
My code looks like this, with a comment that ignores the warning:
//noinspection ConstantConditions: Action bar should always be present. If not, we prefer a NullPointerException here. getSupportActionBar().setHomeButtonEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
source share