-
Notifications
You must be signed in to change notification settings - Fork 2.8k
[MNG-8696] PathModularizationCache needs to set cache #2219
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: master
Are you sure you want to change the base?
Changes from all commits
22005d6
6d5b0bc
55c6669
3ec4731
4150c04
fd4dbc4
e3ac389
36050c7
f12ffd4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -102,19 +102,27 @@ public class DefaultDependencyResolverResult implements DependencyResolverResult | |||||
* to {@link #addDependency(Node, Dependency, Predicate, Path)}. | ||||||
* | ||||||
* @param request the corresponding request | ||||||
* @param cache cache of module information about each dependency | ||||||
* @param exceptions the exceptions that occurred while building the dependency graph | ||||||
* @param root the root node of the dependency graph | ||||||
* @param count estimated number of dependencies | ||||||
*/ | ||||||
public DefaultDependencyResolverResult( | ||||||
DependencyResolverRequest request, List<Exception> exceptions, Node root, int count) { | ||||||
this(request, new PathModularizationCache(), exceptions, root, count); | ||||||
} | ||||||
|
||||||
DefaultDependencyResolverResult( | ||||||
DependencyResolverRequest request, | ||||||
PathModularizationCache cache, | ||||||
List<Exception> exceptions, | ||||||
Node root, | ||||||
int count) { | ||||||
this.request = request; | ||||||
this.cache = cache; | ||||||
if (cache == null) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think that's the same. cache is nullable. We need to create a cache if the argument is null, not throw an exception. Null is passed for this argument and we don't want to break those existing usages. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The new constructor should replace all the calls to the previous constructor with a null cache. We are sure that the new constructor is invoked outside the package since the old constructor became package-private. So we only need to ensure that the calls inside the package pass a non-null cache, and I think that it is already the case. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's risky and brittle to allow null caches given the multiple locations that invoke methods on the cache and the lack of test coverage on this class. It is unsafe to allow this field to be null, even if the constructor argument is. Even if it doesn't cause an uncaught NPE now it will in the future. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes I agree, which is why my proposal above was to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, I don't want to throw a NullPointerException. We can easily create a cache here.. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The rational was that a cache created here is of limited use. The intend was to have a session-wide cache, which is why this method was requesting the cache in argument. The creation of a cache in the constructor was only a temporary workaround for the fact that we have not investigated where a session-wide cache should be stored. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Whatever the intent was, this field is dereferenced without null checks in multiple places. That's dangerous. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I agree that it is dereferenced without null checks, which is why the proposal above was to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
take happy path. |
||||||
this.cache = new PathModularizationCache(); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could init on declaration to give context for default trading coupling for cohesion. This case is then implied default making use for only dedicated second if. |
||||||
} else { | ||||||
this.cache = cache; | ||||||
} | ||||||
this.exceptions = exceptions; | ||||||
this.root = root; | ||||||
nodes = new ArrayList<>(count); | ||||||
|
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.
In the particular case of this issue, creating the cache at the location where the field is defined is the opposite of the intend, because it makes the
PathModularizationCache
lifetime strongly coupled with theDefaultDependencyResolverResult
lifetime. Such coupling makesPathModularizationCache
close to useless. It was done that way in the previous version of this class only as a workaround for the fact that I didn't knew where to store a session-wide cache, but that workaround was intended to be temporary.More details in a next comment.
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.
my suggest would not compile. im sorry.