-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Cleanup usages of addBean(Object)
from constructors
#11317
Comments
I'd be very cautious about such a change. Often beans are used in configuration, which is done before a doStart call. |
If the method call |
The heart of the issue is the passing of We (@sbordet @lorban and I) did a quick review of this scenario in the Jetty 12 codebase. |
The object passed to Perhaps the better "solution" is to move all the addBean calls to be the last thing done in the constructors rather than early on. Not a perfect solution, but we have been adding beans from constructors forever. |
Still won't be fully constructed on abstract usage and calls to |
I understand the issue. But the proposed cure is worse than the disease. Potentially we should deprecate the newly added convenience constructor that passes in a If we still have issues, then we can add a protected |
If we had an |
I think @gregw made a few good points: calling Adding a new method like It's still a behavioral change (maybe someone relies on the listeners being called?), but IMHO that is a small sacrifice. |
How about a smaller fix? See PR #11321 |
I would go simpler and just fix the logging statement and clarify the javadoc that Listeners receive a half-constructed container when I can live with |
Issue #11317 - Low hanging fix for LOG.debug in addBean.
@sbordet during construction, there should be no listeners that installBean needs to call. I've only found one case where an installed bean was itself a listener and it was an easy work around. I'm not 100% convinced we need installBean, but I'll work on the PR and we can see what it looks like. There fix on toString not using this does 95% of what is needed |
Jetty version(s)
12
Jetty Environment
All
Java version/vendor
(use: java -version)
All
OS type/version
All
Description
In the process of working Issue #11220 and the PR #11225 it was discovered that we have a problem with calling virtual methods (like
addBean(Object)
) from constructors where we can wind up with partially initialized classes that are then used / referenced / passed around in different ways.One is the DEBUG logging of addBean with a parameter of
this
...jetty.project/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/component/ContainerLifeCycle.java
Lines 418 to 419 in 7fbd51a
Another is the call to the bean added listeners with
this
parameter during addBean.jetty.project/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/component/ContainerLifeCycle.java
Lines 348 to 350 in 7fbd51a
We should strive to move to a doStart() > addBean() and later call to doStop() > removeBean() (like what is being done in fc32100
The text was updated successfully, but these errors were encountered: