koryphe
koryphe copied to clipboard
Replaced HashSet with LinkedHashSet for deterministic ordering in IsIn
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:
https://github.com/gchq/koryphe/blob/36c63c3e24145e04405d7620524b23cf9b5b5849/core/src/test/java/uk/gov/gchq/koryphe/impl/predicate/IsInTest.java#L53
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:
Please let me know if you want to discuss these changes.
Quality Gate passed
Issues
0 New issues
0 Accepted issues
Measures
0 Security Hotspots
0.0% Coverage on New Code
0.0% Duplication on New Code
Quality Gate passed
Issues
2 New issues
0 Accepted issues
Measures
0 Security Hotspots
0.0% Coverage on New Code
0.0% Duplication on New Code
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.