NullAway: NullAway doesn't recognize Guava Preconditions checks

I’m using Google Guava Preconditions to raise errors on null parameters. So basically, when I write something like:

Preconditions.checkArgument(item != null, "Unable to find an element with name '%s'.", name);
return item;

item is null safe, but NullAway still raises an error.

image

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 21 (1 by maintainers)

Commits related to this issue

Most upvoted comments

This shows up enough internally and asked about externally often enough that we should probably prioritize it above lowpriority. Most cases seem to be reducible to Preconditions.checkNotNull(...). But, as @ketkarameya 's example shows… some are a bit more involved.

There are also cases like this, where there is no null check, but there is a call that implies null checking:

Preconditions.checkArgument(Strings.isNullOrEmpty(s), "blah")

Another flavor of this is scenario is- Preconditions.checkArgument(item != null && someOtherCondition(item), "Unable to find an element with name '%s'.", name); (Note I have a conjunction expression as the first argument).

@jrepe no concrete plans to prioritize this. I would be open to accepting a PR if we could show it doesn’t impact overhead too much (and I don’t think it should).