Skip to content
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

Signature of methods in SchemaElementDefinition #1804

Closed
gaffer01 opened this issue May 24, 2018 · 6 comments · Fixed by #2889
Closed

Signature of methods in SchemaElementDefinition #1804

gaffer01 opened this issue May 24, 2018 · 6 comments · Fixed by #2889
Assignees
Labels
enhancement Improvement to existing functionality/feature

Comments

@gaffer01
Copy link
Member

gaffer01 commented May 24, 2018

In SchemaElementDefinition the signature of the method getGroupBy is to return Set<String>. The actual object that is returned is of type LinkedHashSet. Many callers of this method assume that the results are in a consistent order, e.g. when properties are serialised they need to always be serialised in the same order. As the result is a LinkedHashSet, the results are in a consistent order. But as the signature doesn't guarantee that, in theory the implementation of SchemaElementDefinition could change (to return a HashSet for example) and client code would break as the order would not be consistent.

There are similar issues with getIdentifierMap and getProperties.

EDIT
This branch has attempted a workaround. @d21211122 says:
For Gaffer 2.0, undo the workaround, deprecate these methods and replace them with ones that guarantee a consistent order and update all the callers of the methods in Gaffer to use the new ones.

@gaffer01 gaffer01 added enhancement Improvement to existing functionality/feature p:low labels May 24, 2018
@gaffer01 gaffer01 added this to the Backlog milestone May 24, 2018
@p013570 p013570 modified the milestones: Backlog, v2.0.0 Jun 27, 2018
@m55624 m55624 self-assigned this Oct 17, 2018
@m55624
Copy link
Contributor

m55624 commented Oct 17, 2018

We cannot update the signature as the methods are public, so new ordered methods have been created and the old ones deprecated, as mentioned above.

@m55624 m55624 modified the milestones: v2.0.0, v1.8.0 Oct 17, 2018
m55624 added a commit that referenced this issue Oct 17, 2018
@m55624 m55624 removed the in-review label Oct 17, 2018
@m55624 m55624 modified the milestones: v1.8.0, Backlog Oct 17, 2018
m55624 added a commit that referenced this issue Nov 13, 2018
@m55624
Copy link
Contributor

m55624 commented Nov 13, 2018

The Sets have been updated to Lists and made immutable.

@m55624 m55624 removed their assignment Dec 12, 2018
@n3101 n3101 modified the milestones: Backlog, v2.0.0 Jul 7, 2021
@n3101 n3101 modified the milestones: v2.0.0, v2.0.0-alpha-0.5 Feb 2, 2022
@n3101 n3101 removed the p:low label Feb 2, 2022
@lb324567
Copy link
Member

Need to investigate if this is still a problem, then decide what alpha it needs to go into (if any). If it is a breaking change add the label and ensure it's in an appropriate milestone.

@GCHQDeveloper314
Copy link
Member

The historic comments by @m55624 above (new ordered methods) relate to the branch gh-1804-SchemaElementDefinition-method-signatures, but this was never merged in and these changes have not been applied.

In Gaffer there are many instances of fields declared with the class as an interface from Java Collections and not an implementation. There are also many (200+) public methods returning these classes. Where order is not guaranteed for the Collection's implementation (Set or Map), but calling code relies on order, this problem could occur. However, for this to happen the actual order would need to be lost because of a code change.

In the case of SchemaElementDefinition, there is nothing to suggest that the implementation of groupBy is going to be changed to no longer be ordered. If this change were proposed then method signatures could be altered as part of that.

As the problem of method signatures using interface classes which do not guarantee order is not specific to SchemaElementDefinition and there is nothing to suggest it is a current problem with that class, I'd suggest this ticket be closed. If lack of clarity for ordering of collections in method signatures is considered to be a valid future improvement, then a new issue should be raised for this (such a ticket would include the changes suggested here).

@t92549
Copy link
Contributor

t92549 commented Feb 14, 2023

I have added a PR (#2889) which should satisfy this ticket, rather than explicitly changing the types to be ordered, I have added tests that dictate ordered results

@t92549
Copy link
Contributor

t92549 commented Feb 14, 2023

Closed by #2889

@t92549 t92549 closed this as completed Feb 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improvement to existing functionality/feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants