JSON-java icon indicating copy to clipboard operation
JSON-java copied to clipboard

Issue 652 cycle detection doesnt catch cycles through collections

Open hendrixjoseph opened this issue 1 year ago • 1 comments

For issue #652:

This PR detects cycles through collections. It also adds a unit test to verify that this cycle is detected.

The PR also adds three additional unit tests - one of which passes, two of which fail. The passing one verifies that cycles are detected for simple Objects - this was competed with issue #632 / PR #645.

The two failing ones attempt to verify that a cycle is detected in arrays and maps. This is currently not implemented, and a felt it was outside the scope of this issue and PR. If the tests need to pass before the code is merged, I can add an @Ignore annotation to the two failing tests pending another issue & PR.

hendrixjoseph avatar Oct 20 '22 17:10 hendrixjoseph

The Java 8 test build did fail due to those two intentionally failing tests; let me know if you want me to add @Ignore to them.

hendrixjoseph avatar Oct 20 '22 18:10 hendrixjoseph

@hendrixjoseph Sorry for not responding sooner. Failing unit tests are a concern. What is the performance cost of this change (how much does it slow things down)?

stleary avatar Oct 27 '22 13:10 stleary

@hendrixjoseph Sorry for not responding sooner. Failing unit tests are a concern. What is the performance cost of this change (how much does it slow things down)?

I added an @Ignore to the two failing tests - see the discussion above with @javadev.

As far as performance costs - I didn't measure anything, but it does do a linear search through each list to see if there's an object that will be processes recursively. So it slows it down O(n) for each list (where n is the size of the list). If there are no lists, then there are no performance costs.

hendrixjoseph avatar Oct 28 '22 14:10 hendrixjoseph