-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Add missing @Named annotations for CoinFormatter injection #3658
Add missing @Named annotations for CoinFormatter injection #3658
Conversation
@@ -139,7 +142,7 @@ | |||
public DisputeView(DisputeManager<? extends DisputeList<? extends DisputeList>> disputeManager, | |||
KeyRing keyRing, | |||
TradeManager tradeManager, | |||
CoinFormatter formatter, | |||
@Named(FormattingUtils.BTC_FORMATTER_KEY) CoinFormatter formatter, |
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.
I think in this case it's unnecessary, because this constructor is not annotated with @Inject
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.
That is what I thought too, which is why I left these out originally. But it turns out @inject
is not infact mandatory and the program crashes on these views without this annotation. Thanks to @stejbac for discovering this.
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.
Are you sure that app crash when you ommit @Named
annotation on this particular file (DisputeView
) ? It's an abstract class and it does not "participate" in dependency injection.
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.
On second thought, I might have been wrong about @Inject
not being mandatory for Guice, since looking closer the modified Dispute*
classes all have subclasses with @Inject
-annotated constructors - probably only TransactionsView
and TakeOfferView
actually needed fixing. (I'm pretty sure it isn't mandatory by default for Spring, but perhaps Guice is stricter.)
Also, there are (probably leftover) @FxmlView
annotations on the 3 Dispute*
classes which mislead me to think that they were concrete components - perhaps those annotations can be removed?
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.
I think here it is not necessary as mentioned by @lusarz. At least it didn't crash for me here.
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.
But it turns out
@inject
is not infact mandatory and the program crashes on these views without this annotation.
Did it crash for you while testing?
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.
I agree that probably only these two views needs to be annotated.
Yeah, I suppose @FxmlView
on abstract views are leftovers, and it would be nice to remove them.
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.
Inject annotation is needed for the concrete classes but not for the base classes (should not be used there). It probably crashed due some nullpointers caused if the annotation is missing but with view classed you don't get proper error logs.
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.
Inject annotation is needed for the concrete classes but not for the base classes (should not be used there). It probably crashed due some nullpointers caused if the annotation is missing but with view classed you don't get proper error logs.
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.
NACK - please see my comments
@@ -139,7 +142,7 @@ | |||
public DisputeView(DisputeManager<? extends DisputeList<? extends DisputeList>> disputeManager, | |||
KeyRing keyRing, | |||
TradeManager tradeManager, | |||
CoinFormatter formatter, | |||
@Named(FormattingUtils.BTC_FORMATTER_KEY) CoinFormatter formatter, |
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.
I think here it is not necessary as mentioned by @lusarz. At least it didn't crash for me here.
@@ -48,7 +49,7 @@ | |||
public DisputeAgentView(DisputeManager<? extends DisputeList<? extends DisputeList>> disputeManager, | |||
KeyRing keyRing, | |||
TradeManager tradeManager, | |||
CoinFormatter formatter, | |||
@Named(FormattingUtils.BTC_FORMATTER_KEY) CoinFormatter formatter, |
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.
I think here it is not necessary.
@FxmlView | ||
public abstract class DisputeClientView extends DisputeView { | ||
public DisputeClientView(DisputeManager<? extends DisputeList<? extends DisputeList>> DisputeManager, | ||
KeyRing keyRing, | ||
TradeManager tradeManager, | ||
CoinFormatter formatter, | ||
@Named(FormattingUtils.BTC_FORMATTER_KEY) CoinFormatter formatter, |
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.
I think here it is not necessary.
One more question: Is there a reason why we use for these injects the Named annotation from javax.inject.Named and on other places com.google.inject.name.Named? |
It seems both work the same as described in https://github.com/google/guice/wiki/JSR330 |
@ripcurlx I think there is no reason - I suppose everyone use autoimport feature in Intellij and no one cares which one is imported :) |
7a92f63
to
90f523a
Compare
@bodymindarts It looks like you still left the unused imports in and a small typo in the commit message |
I have force pushed removing the annotation from the abstract classes. I have consistently used
To mirror the usage of
These are library agnostic and should still be effective if a different DI framework is used. I didn't notice that another import was used elsewhere. |
I guess we should get rid of the Guice bound annotations in favor of the generic one at some point. |
90f523a
to
40d0376
Compare
Removed the unused imports |
40d0376
to
88d031f
Compare
And commit message is no typo. If you look at the message locally its fine. It seems to be a display bug in github. |
Yes it looks like GitHub tries to be clever finding a user with that name 🤦♂ |
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.
ACK
@bodymindarts Would you prepare pull request that removes unnecessary |
I missed a few places where
@Named(BTC_FORMATTER_KEY)
annotation should be added in my recent PR #3634.