I have this method to get child count from a recycler view, but it is throwing spotbug error
A failure occurred while executing com.github.spotbugs.snom.internal.SpotBugsRunnerForHybrid$SpotBugsExecutor Verification failed: SpotBugs ended with exit code 3See the report at: NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE - Possible null pointer dereferenc ...matchesSafely(View) due to return value of called method
public static int getCountFromRecyclerView(@IdRes int RecyclerViewId) {
final int[] COUNT = {
0
};
Matcher matcher = new TypeSafeMatcher < View > () {
@Override
protected boolean matchesSafely(View item) {
COUNT[0] = ((RecyclerView) item).getAdapter().getItemCount();
return true;
}
@Override
public void describeTo(Description description) {}
};
onView(allOf(withId(RecyclerViewId), isDisplayed())).check(matches(matcher));
return COUNT[0];
}
Tried adding Objects.requireNonNull and @SuppressFBWarnings("NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE"). Nothing seems to work.
This block is the reason for the error
protected boolean matchesSafely(View item) {
COUNT[0] = ((RecyclerView) item).getAdapter().getItemCount();
return true;