Skip to content
This repository was archived by the owner on Aug 20, 2025. It is now read-only.

Add check for nullability mismatch.#149

Open
runningcode wants to merge 1 commit intoJakeWharton:masterfrom
runningcode:no/checknullability
Open

Add check for nullability mismatch.#149
runningcode wants to merge 1 commit intoJakeWharton:masterfrom
runningcode:no/checknullability

Conversation

@runningcode
Copy link
Copy Markdown
Contributor

When there is a mismatch between the nullability of the binding and the
requestor, throw an exception.

This only works if the nullability annotations have runtime retention.

Looking for feedback to see if this is a reasonable approach and how/if we should make the error message better.


@Override
public @Nullable Object invoke(Object[] args) {
if (binding instanceof LinkedProvidesBinding) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BindsInstance could also have @Nullable can't it?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I think there needs to be something like a isNullable on Binding until type annotations save us from this nonsense. And then anyone requesting a Binding will have to validate that the consumer can handle null.

@runningcode
Copy link
Copy Markdown
Contributor Author

runningcode commented Jul 21, 2019

Hmm, should we introduce DependencyRequest to dagger reflect?
I feel like it would add a good bit of runtime overhead to create one for each DepenencyRequest.

When there is a mismatch between the nullability of the binding and the
requestor, throw an exception.

This only works if the nullability annotations have runtime retention.
@runningcode runningcode force-pushed the no/checknullability branch from d97b3b6 to 51a9180 Compare July 21, 2019 20:57
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants