-
Notifications
You must be signed in to change notification settings - Fork 25.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Injector allows binding undefined, provide
function does not fail when incorrectly used
#8870
Comments
This also happens when using the provider literals, e.g. the following code is wrong as the class is declared after the provider, but this is super hard to debug right now.
/cc @vsavkin |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Current behavior
It's very easy to get incorrect behaviour out of the injector, e.g. by accidentally forgetting to pass an object literal to
provide
. For example, the following will silently fail and bindundefined
toMyFoo
.Expected/desired behavior
This should fail on two levels:
provide
should check its arguments, and if none of the arguments are defined, given an error.undefined
, and probably also impossible to bindnull
.undefined
is a common error (some import or property is missing, something went wrong)Allowing to bind
null
means the code that gets instantiated by the injector gets a ctor parameter (field, whatever) that does not satisfy the contract the injected code expects; doing anything with it will fail. This means very hard to debug error cases, where once the app is running, much later something somewhere fails. Guice handles this by requiring bindings to be annotated as@Nullable
if they should take null, but I think we might as well just disallow it; passingnull
values long distance through a large software system is prone to create very hard to debug error cases.The text was updated successfully, but these errors were encountered: