-
Notifications
You must be signed in to change notification settings - Fork 3
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
Java equality on Variable #10
Comments
Just to add that I think this will also be a problem in m2m with Epsilon for |
@pefribeiro I think the motivation for this was the validation and possibly the semantics. The kind of situation where we might have a problem is this. However, if the lack of implementation of hash is a problem with collections, the validation may not be working. It may be the case that all the tests use the same interfaces to require and provide or define variables, so the variables are effectively always the same. I'll create a test to check this and let you know the result. Have you run the generator tests with this change? |
I think that uses a List, so duplicates are fine, in which case the equality/hashcode should not be relevant. When implementing the RoboSim semantics I faced similar issues, where I wanted to use Sets, but because the objects differ, I resorted to implementing wrappers that define their own equals/hashcode, exactly to circumvent the problem. To me this suggests no use of Sets would be affected as far as I can see, and Lists have duplicates anyway.
Ok.
I have, but just on just a few examples. If I can get maven to build locally based on the modified version I could have a go and run the tests. |
@alvarohm I've now built this locally and then run the RoboChart csp generator tests and they all pass when equals is not overridden for both Variable and Parameter. |
robochart-metamodel. See: UoY-RoboStar/robochart-metamodel#10
NOTE: need to update main.yaml for deployment, if, and when, we're are to fix this. |
Updating main.yml so it can be deployed in the future, eg. when fixing issue #10.
One additional note on this issue. I haven't changed the equals on OperationSigImpl, but I wonder if that too should be removed, given that it doesn't implement the hashcode overriding properly? |
@pefribeiro I have been testing the change and noticed one issue with required variables. While the matching of required and provided variables works when using interfaces, if we try to satisfy a required variable of a state machine with a variable directly defined in the controller, this fails because the variables are not equal. Below is the example:
RoboTool raises an error: One solution to this that I have used in another language I developed is to implement equals and hashCode, but this would require a way of calculating the hashCode of the type in such a way that different instances of the same type have the same hashCode. I've done this in the other language by converting the type into a separate type representation that controlled the hashCode well, but this may be too much work here. Alternatively, we could modify the validator where variable comparisons are made. I have tested a small change to the validator to use expressions like
This expression is used instead of With these changes, RoboTool does not raise any errors for the example above. In fact, now the validator is more powerful because it is taking the types into account when comparing variables. Let me know what you think and I'll commit the changes. |
Hi @alvarohm, Good observation. I don't think I caught all problems in the changes I made in UoY-RoboStar/robochart-textual@6791d06, but they closely follow your second approach. I think that is ok and ok to proceed. In my opinion, it's better than messing with the hashCode, which would leave us with the same problem as before. I don't think we should distinguish these objects in Java. If that is necessary, I suggest wrapping the objects into classes that implement the hashCode/equality as needed, which is roughly what I ended up doing for the RoboSim generator whenever I use sets with elements from different contexts, like events/variables and so on. |
@pefribeiro Sorry, I missed those changes. Weird to come up with an almost identical solution. I'll add the null check's you've used and commit the changes. |
@alvarohm No problem. Sorry for not mentioning it explicitly before. |
@alvarohm I have tested both the branch(var-equality) of textual with the branch (var-no-equality) of metamodel. Your new commit has fixed the same issue (I reported through email). Now, this fix works for all my six examples. |
I propose that we accept the current solutions in the branches var-no-equality of the metamodel and var-equality of the textual editor. I'll create pull requests for these branches. |
Ok @alvarohm and @RandallYe. Thanks for the tests. I think we can proceed. |
pull request #12 partially addresses this issue |
I have also created a pull request for the textual editor here |
Merging changes that address issue #10.
Now that the metamodel has been updated, merging changes related to UoY-RoboStar/robochart-metamodel#10.
@madielfilho has hit a problem in model-transformation using Epsilon (ETL) because equality on RoboChart
Variable
s is over names. While I understand the motivation, this makes it impossible to decide if twoVariable
objects are actually the same in Java, and hence in Epsilon for the purpose of m2m transformations. The relevant code is below:robochart-metamodel/circus.robocalc.robochart/src/circus/robocalc/robochart/impl/VariableImplCustom.java
Lines 9 to 19 in 06a6b46
I've commented the code and the issue in Epsilon goes away. @alvarohm what is the implication of removing this custom equality?
I also note that just overriding
equals
isn't adequate. The Java documenation on Objects states thatso actually the hashCode should have also been overridden here. But given that it isn't, I expect that this equality is not really behaving in the expected way (eg. in Java collections, as I suspect they do use hashCode internally in things like
HashSet
s). So perhaps the impact of removing this custom overriding is not as large?I also tried implementing the hashCode correctly (ie. by returning
Objects.hash(this.getName());
) and the validator started having issues. Removing the overriding onequals
had no impact on validation as far as I could tell. Further testing is needed to gauge the impact of this on other plug-ins.I have seen that other metamodel classes have also had the equality overridden. I'm not aware of other problems, but there could be similar issues for model transformation later on.
The text was updated successfully, but these errors were encountered: