-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
fix(#4218): avoid duplicate injection on fields #5224
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
base: 2.x
Are you sure you want to change the base?
fix(#4218): avoid duplicate injection on fields #5224
Conversation
…sponding injected constructor parameter is available
@@ -816,6 +816,9 @@ protected void addInjectables(DeserializationContext ctxt, | |||
|
|||
for (Map.Entry<Object, AnnotatedMember> entry : raw.entrySet()) { | |||
AnnotatedMember m = entry.getValue(); | |||
if (m.isIgnoreInjection()) { |
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 avoid creating a redundant ValueInjector
for fields whose injection was already performed via constructor properties.
* | ||
* @since 2.20 | ||
*/ | ||
protected boolean _ignoreInjection; |
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.
AnnotatedMember
s cannot have per-call state (one instance created perAnnotatedClass
; concurrentreadValue()
calls would have conflict).So this cannot be done.
Ignore above, I misread code.
I like the concept, although would prefer not adding configuring state in |
After a quite deep analysis on #4218, I ended up implementing what was also suggested in this comment.
This way, when there are both creator properties and fields with the same injection, we mark the annotated field to be ignored when creating the corresponding injectable.
We ignore fields instead of constructor properties considering that constructor injection happens before field injection, and users may need the injected value in the constructor to do any additional logic on their side.
This seems to solve #2678 as well.
Waiting for feedbacks and improvements