-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Remove unnecessary MembersInjectors.injectMembers
method
#950
Conversation
* members, so care should be taken to ensure appropriate use. | ||
*/ | ||
@SuppressWarnings("unchecked") | ||
public static <T> MembersInjector<T> noOp() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We may not have a test for it, but this is returned when for types that have no injected members:
class A {
@Inject A() {}
}
@Component
interface C {
MembersInjector<A> aMembersInjector();
}
} | ||
} | ||
|
||
public static void checkInstanceNotNull(Object instance) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is use above, but we can make it private
probably
@@ -79,7 +78,6 @@ | |||
static final ClassName MAP_PRODUCER = ClassName.get(MapProducer.class); | |||
static final ClassName MAP_PROVIDER_FACTORY = ClassName.get(MapProviderFactory.class); | |||
static final ClassName MEMBERS_INJECTOR = ClassName.get(MembersInjector.class); | |||
static final ClassName MEMBERS_INJECTORS = ClassName.get(MembersInjectors.class); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See MemberSelect.noOpMembersInjector()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, right.
So can I remove static injectMembers
from MembersInjectors
?. It's seems to be not used.
@@ -57,7 +48,7 @@ | |||
} | |||
} | |||
|
|||
public static void checkInstanceNotNull(Object instance) { | |||
private static void checkInstanceNotNull(Object instance) { | |||
checkNotNull(instance, "Cannot inject members into a null reference"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe just inline this above?
MembersInjectors.injectMembers
method
Great, thanks! We'll submit this internally and then sync a commit with your authorship here! |
Closes #950 RELNOTES=n/a ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=175736999
Hi, I am using a dependency which is built with old version of dagger. After updating to Exception description Generated code from library public OverlayPresenter get() {
return (OverlayPresenter)MembersInjectors.injectMembers(this.overlayPresenterMembersInjector, new OverlayPresenter((PresenterConfiguration)this.presenterConfigurationProvider.get(), (BusinessInteractor)this.businessInteractorProvider.get()));
} I am not sure how to fix it, can you help please? |
You should shade the |
Any reason we did breaking changes to a "public" api? |
Strongly disagree. The nature of generated code is such that many things
have visibilities beyond what you'd otherwise desire in order to facilitate
the functionality.
Perhaps an annotation and error-prone check can enforce true public API for
@generated code.
…On Wed, Jan 24, 2018 at 3:46 PM Vladimir Baryshnikov < ***@***.***> wrote:
Any reason we did breaking changes to a "public" api?
It is not really internal if it is end up being used by client code, even
if it is autogenerated.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#950 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAEEEbsII1kDNhMjyNT4HNilPiUDCxNyks5tN5akgaJpZM4Qd56O>
.
|
It's a good idea to be shading any |
@JakeWharton That is all ok if you have access to code to generate. If you are building a library using dagger, all code generation is already done. So we either should not change "public" api to keep it compatible, or we should do real client code generation to make sure there is no dagger dependencies left to worry about, i.e. internals should not be on a class path, generate anything you may need in clients namespace. |
I have to agree with @vovkab here, if generated code depends on |
I facing this issue as well
What does the |
To https://maven.apache.org/plugins/maven-shade-plugin/ or anything similar for your build tool (e.g. https://imperceptiblethoughts.com/shadow/ for Gradle, https://github.com/google/bazel-common/blob/c0a6655a70fb389dbb6473989450df0c86447ec3/tools/jarjar/jarjar.bzl for Bazel, etc.) |
Thanks @tbroyer. I'm using gradle (Android Studio). What if I don't have control over the jar where I can't make changes to it, is there anything I could do? P/S: I tried
Can I assume if the library uses the same dagger version as mine (e.g. both of us move to 2.19), then this would not be an issue? |
I don't think this is going to work, this is the same as just specifying latest version. The idea is that you would create local copy of the dagger library just with the different package name, so they all could co-exist in a single project. Though I think this is only would work for your app, not sure if you can repackage 3rd party libraries (or maybe you can?).
Yes, if your app and libraries use "compatible" dagger versions it would work, they don't have to use the same version. p.s. this is really a pain for us, if we have 20 libraries that use 20 different versions of dagger and all these dagger versions are incompatible, we would need to repackage 20 libraries and 20 versions of dagger :'( |
There's no guarantee that the generated code (i.e. factories) work well with each other across versions. We don't have any way of testing that. It's a generally good idea that any libraries that are intended to use Dagger in tandem are using the same version of Dagger. If a library you don't own is passing along Dagger codegen to you and isn't documenting it, that's a bad idea on the library owners part. In fairness, we don't really have a good way to share libraries across project owners that guaranteed support across multiple versions. |
They don't have to be, this is pre-generated code, the problem is in code that ships in dagger jar.
In my opinion, this really should not matter, this is an internal library code.
We actually do, here are a couple suggestions:
|
This is still an issue, for example now even google is packaging dagger2 into their libraries without creating a shadowed version:
What this means is that if dagger library again introduce breaking change like this one, we would be stuck with 2.27 until google decide to update dagger version. What makes it even worse is that other libraries may use different versions of dagger which would be incompatible between each other. Here is the firebase bug: |
The last use of theMembersInjectors
class was removed in this commit, so it isn't used now during code generation.(This class is still used in
TypeNames
as a class name constant, which is no longer necessary)Static
MembersInjectors.injectMembers
is no longer used during code generation.