google / google/EarlGrey

`GREYElementMatcherBlock` not respecting that `item` can be nil.

Open
#725 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Objective-C
Stars
5.7k
Forks
737
Avg merge
1d 20h
Merged PRs (30d)
5

Description

[GREYBaseMatcher](https://github.com/google/EarlGrey/blob/1d507003e3c436c2db89d0945e3d23f7bf25ac2b/EarlGrey/Matcher/GREYBaseMatcher.h) indicates that the element passed to `- (BOOL)matches:(_Nullable id)item;` can be null. However [GREYElementMatcherBlock](https://github.com/google/EarlGrey/blob/1d507003e3c436c2db89d0945e3d23f7bf25ac2b/EarlGrey/Matcher/GREYElementMatcherBlock.m) defines `MatchesBlock` with a non-null item and does not check the item for nil before calling the block. This results in `EXEC_BAC_ACCESS` when using Swift on Xcode 9.3.

`GREYElementMatcherBlock.m` should change its `matches` method to:

```Objective-C
- (BOOL)matches:(id)item {
if (!item) return NO;
return _matcherBlock(item);
}
```

I'm sorry that I didn't create a PR. I discovered this at work and I have to go through an open source review process to submit a PR. It looks like 1.14.0 is close to being released and getting through my works approval process takes a long time.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Open EarlGrey/Matcher/GREYElementMatcherBlock.m and inspect the matches: method and its MatchesBlock definition. Confirm that a nil item is handled without invoking the block and returns NO, while non-nil matching still behaves as before.

Written by the indexing model from the issue text.

Assessment

Tech stack
ios, objective-c
Domain
mobile-dev, testing-qa
Issue type
Bug
Difficulty
1/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
50/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.