-
Notifications
You must be signed in to change notification settings - Fork 116
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
MavenTargetLocation equals comparison never returns true #1649
Conversation
2bbd68e
to
4eb7a21
Compare
@haubi you need to increment the version for this change. One thing I wonder is if we should move the equals check if the location to |
Agreed, having the equals check in Meanwhile, it turns out that |
4eb7a21
to
2955180
Compare
c53df64
to
6d1ca3b
Compare
6d1ca3b
to
a816490
Compare
a816490
to
0fa9047
Compare
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 general one could consider to cache the result of serialize()
in order to speed-up equals(), but I assume that method is not called that often for a MavenTargetLocation
so it is probably not relevant, is it?
0fa9047
to
9c6c79a
Compare
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.
After thinking about this again, we should cache the result of serialize()
, either in the serialize()
method itself, computing the value lazy or in the constructor where we could consider to even use the original string from which the target was parsed (if so).
&& Objects.equals(dependencyScopes, other.dependencyScopes) | ||
&& Objects.equals(failedArtifacts, other.failedArtifacts); | ||
// check each and every relevant attribute, including nested ones | ||
&& serialize().equals(other.serialize()); |
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.
If equals is changed, hashCode() should be adjusted in the same way.
9c6c79a
to
26bbd40
Compare
In the TargetPlatformPreferencePage, upon the Apply button, some target definition containing some MavenTargetLocation always was rewritten to it's .target file. This was because MavenTargetLocation.equals never returned true for multiple reasons, starting with MavenTargetDependency lacking an impl of equals(). Using serialize(), we can be sure to perform the equals check on any relevant attribute, including deeply nested ones. Beyond that, also use serialize() to implement hashCode().
26bbd40
to
e8ced44
Compare
@haubi what I'm wondering and as you have already analyzed that, can you probably point out where exactly the equals check fails in the PDE code? I wondering if instead of changing m2e, it might generally be better to change the code there to always check the |
Using serialize() for hashCode() is fine with me. While I understand the motivation behind caching the serialize() value, I believe we are unable to catch each and every situation where (deeply nested) attributes can be modified, which would require the cached value to be flushed. |
Maven Target locations should be immutable already, do you see any mutated state here? |
@laeubi Well, here's my journey:
Not sure where you mean by "there", but indeed I have thought on something similar too: |
You mentions that you faced "In the TargetPlatformPreferencePage, upon the Apply button, some target definition containing some MavenTargetLocation always is rewritten to it's .target file" So I would think about that lets say there is even other location types, maybe this check should be enhanced "there" (in the
so just roughly speaking, parse the XML of previous state and compare it with the parsed XML on new state to decide if something has to change and if not keep the file as is. So given a location always produces the same XML equivalent (not necessary text representation) it should never touch the file. |
Well, maybe I'm misinterpreting, but this is what makes me believe it should be mutable:
|
Well,
Feels like not using |
Yes I think As mentioned the order of locations is irrelevant (what is currently checked!) and the locations itself are better compared by their serialized representation instead of their object representation! |
@laeubi Did I understand it correctly in that you want something like: |
@haubi yes, sorry for the confusion here but I think that is much more felxible and usefull than what we can do here at m2e (even though equals/hashcode should be improved of course! |
@laeubi Well, it turns out that not each implementation of |
Yes this is some left overs from "old implementation, best actually would be to implement serialize always in the container ... thats really a mess. |
@haubi is this now obsolete since eclipse-pde/eclipse.pde#1127 is submitted? |
Sure! |
@haubi thanks for working on this one! |
In the TargetPlatformPreferencePage, upon the Apply button, some target definition containing some MavenTargetLocation always is rewritten to it's .target file, when MavenTargetDependency lacks an impl of equals(), causing MavenTargetLocation.roots to never be equal.