Skip to content
This repository was archived by the owner on Mar 16, 2021. It is now read-only.

Feature: getViewOrThrow() in onAttachView() Lint-Check#160

Closed
jreehuis wants to merge 13 commits into
GCX-HCI:masterfrom
jreehuis:feature/lintcheck_getvieworthrow_in_onattach
Closed

Feature: getViewOrThrow() in onAttachView() Lint-Check#160
jreehuis wants to merge 13 commits into
GCX-HCI:masterfrom
jreehuis:feature/lintcheck_getvieworthrow_in_onattach

Conversation

@jreehuis

Copy link
Copy Markdown

Description

This PR implements a new lint check to detect a direct or transitive call of TiPresenter.getViewOrThrow() in TiPresenter.onAttachView().

In TiPresenter.onAttachView() the view of the presenter might still be null. So calling TiPresenter.getViewOrThrow() would throw an exception during runtime.
In production this usually crashes the App. This behaviour is correct to detect the issue later on.

With this lint check the issue can be easily detected already during development.

Merge Information

Merge after #158 as this PR uses the Lint Check implementation of #158 as foundation.

@StefMa StefMa changed the base branch from master to feature/composition September 24, 2018 13:03
@StefMa StefMa changed the base branch from feature/composition to master September 24, 2018 13:03
@StefMa

StefMa commented Sep 24, 2018

Copy link
Copy Markdown
Contributor

In TiPresenter.onAttachView() the view of the presenter might still be null.

How can this happen? 🤔

So calling TiPresenter.getViewOrThrow() would throw an exception during runtime.

Why should someone call getViewOrThrow() instead of using the given View from the method?

Do we need to update the annotation here - when its possible to have a nullable View?
https://github.com/grandcentrix/ThirtyInch/blob/d761dbe800d935cd24a2e813ffd08ccdc4dddf61/thirtyinch/src/main/java/net/grandcentrix/thirtyinch/TiPresenter.java#L507

@passsy

passsy commented Sep 24, 2018

Copy link
Copy Markdown
Contributor

getViewOrThrow() never returns null in onAttachView.

This lint warning could hint to use the parameter view instead of getViewOrThrow()

@jreehuis jreehuis closed this by deleting the head repository Apr 30, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Development

Successfully merging this pull request may close these issues.

4 participants