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

Replaced HashSet with LinkedHashSet for deterministic ordering in IsIn #322

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

mumbler6
Copy link

@mumbler6 mumbler6 commented Oct 3, 2024

The indeterministic ordering of a HashSet in the IsIn class causes the ordering of objects when serialized (to a JSON string) to be inconsistent sometimes. The following test case fails if this happens:

public void shouldJsonSerialiseAndDeserialise() throws IOException {

This PR proposes to replace the HashSet in the IsIn class with a LinkedHashSet, maintaining insertion order so that the test case is correct. It didn't make sense to me to simply change the test case, since the test case is testing serialization of the IsIn class and is comparing two JSON strings, which cannot be sorted or really manipulated.

This change was confirmed by running the NonDex tool, which explores and reports errors in different behaviors of under-determined Java APIs.

To reproduce this problem, you can run the test with NonDex using these commands:

mvn install -pl core -am -DskipTests

mvn -pl core edu.illinois:nondex-maven-plugin:2.1.7:nondex -Dtest=uk.gov.gchq.koryphe.impl.predicate.IsInTest#shouldJsonSerialiseAndDeserialise

Here are screenshots of the output produced by NonDex before and after the fix:
image
image

Please let me know if you want to discuss these changes.

@CLAassistant
Copy link

CLAassistant commented Oct 3, 2024

CLA assistant check
All committers have signed the CLA.

Copy link

sonarqubecloud bot commented Oct 3, 2024

Copy link
Member

@GCHQDeveloper314 GCHQDeveloper314 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test will fail if the order is different, but this is more of a problem with the test, as the order doesn't matter outside that test. On the other hand, I don't think changing the Set to be ordered has much of a disadvantage.

I attempted to edit the branch to make some minor changes, but you have not granted permission to allow edits from maintainers.

Co-authored-by: GCHQDeveloper314 <94527357+GCHQDeveloper314@users.noreply.github.com>
Copy link

sonarqubecloud bot commented Jan 4, 2025

@mumbler6
Copy link
Author

mumbler6 commented Jan 4, 2025

Ah, I understand. When I made this PR, I thought it made more sense to make changes to the underlying implementation but it's clear that is not necessary. You should be able to make edits to the branch, as I've should've checked that setting in this image.

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants