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 1 commit 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

sonarcloud bot commented Oct 3, 2024

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.

2 participants