eclipse / kapua

Eclipse Public License 2.0
225 stars 160 forks source link

Fix/avoid nested locators #3968

Closed dseurotech closed 8 months ago

dseurotech commented 8 months ago

Safeguard to avoid nested creation of KapuaLocator singletons. Without this patch, if a class instantiated within Guice's startup (part of a Module of being automatically instantiated by virtue of having a parameterless public constructor, or one annotated via @Inject) AND it referenced KapuaLocator.getInstance() in the constructor code (or in STATIC assignments), this resulted in a nested creation of a KapuaLocator instance, with duplicate objects in memory, and potential for race conditions (in case, for example, a queue consumer was instantiated).

Description of the solution adopted This patch makes sure no nested instantiations are possible, failing at startup time instead of creating nested contexts.

codecov[bot] commented 8 months ago

Codecov Report

Attention: 11 lines in your changes are missing coverage. Please review.

Comparison is base (2523d9d) 21.18% compared to head (f0b0f40) 21.19%. Report is 5 commits behind head on develop.

Additional details and impacted files [![Impacted file tree graph](https://app.codecov.io/gh/eclipse/kapua/pull/3968/graphs/tree.svg?width=650&height=150&src=pr&token=1P4N4CApH8&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=eclipse)](https://app.codecov.io/gh/eclipse/kapua/pull/3968?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=eclipse) ```diff @@ Coverage Diff @@ ## develop #3968 +/- ## ========================================== Coverage 21.18% 21.19% Complexity 10 10 ========================================== Files 1939 1939 Lines 41199 41207 +8 Branches 3782 3782 ========================================== + Hits 8729 8732 +3 - Misses 32064 32069 +5 Partials 406 406 ``` | [Files](https://app.codecov.io/gh/eclipse/kapua/pull/3968?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=eclipse) | Coverage Δ | | |---|---|---| | [...n/java/org/eclipse/kapua/locator/KapuaLocator.java](https://app.codecov.io/gh/eclipse/kapua/pull/3968?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=eclipse#diff-c2VydmljZS9hcGkvc3JjL21haW4vamF2YS9vcmcvZWNsaXBzZS9rYXB1YS9sb2NhdG9yL0thcHVhTG9jYXRvci5qYXZh) | `51.28% <25.00%> (-3.01%)` | :arrow_down: | | [...eclipse/kapua/client/security/MessageListener.java](https://app.codecov.io/gh/eclipse/kapua/pull/3968?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=eclipse#diff-Y2xpZW50L3NlY3VyaXR5L3NyYy9tYWluL2phdmEvb3JnL2VjbGlwc2Uva2FwdWEvY2xpZW50L3NlY3VyaXR5L01lc3NhZ2VMaXN0ZW5lci5qYXZh) | `0.00% <0.00%> (ø)` | | ... and [1 file with indirect coverage changes](https://app.codecov.io/gh/eclipse/kapua/pull/3968/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=eclipse)