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

Issue 652 cycle detection doesnt catch cycles through collections #699

Conversation

hendrixjoseph
Copy link

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
Copy link
Author

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.

@stleary
Copy link
Owner

stleary commented Oct 27, 2022

@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)?

new JSONObject(new RecursiveList());
}

@Ignore
Copy link
Contributor

Choose a reason for hiding this comment

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

Why?

Copy link
Author

Choose a reason for hiding this comment

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

Why the new JSONObject(new RecursiveList()); or why the @Ignore?

The new JSONObject(new RecursiveList()); is testing if it throws the right exception if the list contains the object which has the list.

The @Ignore (and there's two of them) are for two additional locations where I identified stack overflows when having the object-within-something - one case is within a Map, one case is within an array. Since I didn't fix them as part of this PR (I felt it was out of scope), I added the @Ignore annotation so I could show where the stack overflows were happening, but not have the test fail.

Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need code that will be ignored? It may be an exception check or just remove it.

@hendrixjoseph
Copy link
Author

@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.

@stleary
Copy link
Owner

stleary commented Jan 5, 2023

@hendrixjoseph Thanks for the PR, but I think it will impact execution time for large, nested collections.

@stleary stleary closed this Jan 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants