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

IPAddressSeqRange.join joins upper addresses incorrectly #37

Closed
raymundane opened this issue Apr 6, 2020 · 4 comments
Closed

IPAddressSeqRange.join joins upper addresses incorrectly #37

raymundane opened this issue Apr 6, 2020 · 4 comments

Comments

@raymundane
Copy link

raymundane commented Apr 6, 2020

Hello,

First, thanks Sean for providing and maintaining this library. It has really been a lifesaver!

I think I found a bug in IPAddressSeqRange.join.

Imagine attempting to join two ranges, 10.120.20.10 - 10.120.20.14 and 10.120.20.14 - 10.120.20.20. If the second range's lower is less than or equal to the first range's upper, then it

  1. sets the second range to null, and
  2. returns the first range, except with the first range's upper set to the second range's upper.

This results in 10.120.20.10 - 10.120.20.20, which is correct.

However, using the same logic for 10.120.20.10 - 10.120.20.20 and 10.120.20.15 - 10.120.20.15 will result in 10.120.20.10 - 10.120.20.15, which is incorrect.
Instead of always taking the second range's upper, I feel like the correct thing to do is take whichever upper is greater between the first range and the second. Thoughts?

edit: I'm using version 5.1.0 for Java 11, but I believe it is still present on 5.2.1.

edit2: Also, sidenote but I believe this method mutates the array which is passed in. Reading the javadoc, I'm not sure if this was intentional so I thought I'd mention it.

@seancfoley
Copy link
Owner

Yes, you are correct, on both counts, the method is not selecting the max upper, which is a bug, and also when passing in array instead of varargs the array is mutated, which is not intended behaviour.

@raymundane
Copy link
Author

Thanks for confirming! I will use a temporary fix in my code for now and switch back to IPAddressSeqRange.join upon the next release 👍

@seancfoley
Copy link
Owner

The fix is included in version 5.3.0 now available from the releases page, from maven central, or from bintray

@seancfoley
Copy link
Owner

BTW, thanks for the bug report

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

No branches or pull requests

2 participants