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

Proposed fix : Disallow replacing nodes with themselves #1844

Closed
wants to merge 1 commit into from

Conversation

jdngray77
Copy link

@jdngray77 jdngray77 commented Sep 22, 2022

fixes #1843 : Node.replaceWith deletes siblings and creates an invalid state if a node is replaced with itself.

Proposed changes :

  • Equality validation, throw a ValidationException just as any other invalid parameter would.
  • Unit test for edge case

And add a test for this edge case

closes jhy#1843
@FanJups
Copy link

FanJups commented Sep 24, 2022

Thanks for this correction 💯

@jdngray77
Copy link
Author

jdngray77 commented Sep 24, 2022

@FanJups My apologies, I typed the wrong issue number - this is unrelated to your problem of self closing tags.

Sorry for getting your hopes up lol

@FanJups
Copy link

FanJups commented Sep 24, 2022

all right lol

* @param message Error message to use if the objects are the same
* @throws IllegalArgumentException if the objects are the same
*/
public static void notStrictlyEqual(Object a, Object b, String message) {
Copy link
Owner

Choose a reason for hiding this comment

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

Personally, I would call this method something like "NotSameObject". To make it clearer that it's an identity check.

@jhy
Copy link
Owner

jhy commented Jan 5, 2023

Thanks for the PR and the bug report.

I think that it would be better to make this a no-op vs a validation error. It follows closer to the developer's intent (whatever that was) and is not surprising.

I.e., if (this == in) return

And then the new validator is not required either.

Copy link
Owner

@jhy jhy left a comment

Choose a reason for hiding this comment

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

As noted inline -- would be better if it was a no-op vs a Validation Error.

@jhy
Copy link
Owner

jhy commented Jan 19, 2023

I implemented this with 9bb07d2

@jhy jhy closed this Jan 19, 2023
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.

Replacing an element with itself causes problems.
3 participants