Fix:Harden ULongArray.reorder() validation and improve subset edge-case safety#438
Open
vishwas-droid wants to merge 1 commit intoERDDAP:mainfrom
Open
Fix:Harden ULongArray.reorder() validation and improve subset edge-case safety#438vishwas-droid wants to merge 1 commit intoERDDAP:mainfrom
vishwas-droid wants to merge 1 commit intoERDDAP:mainfrom
Conversation
Contributor
|
This looks to me like it will be slower and with minimal improvement for actual usage (for example if the rank array is invalid most likely it will throw an index out of range exception already). Is this solving a problem, or just a theoretical problem that AI picked? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
While reviewing ULongArray, I noticed that reorder() relied on implicit
assumptions about the provided rank array. There were no checks for null
input, length mismatch, or out-of-range indices. In certain edge cases,
this could lead to ArrayIndexOutOfBoundsException or unintended data
corruption.
This change introduces explicit validation to ensure the rank array
matches the current size and contains only valid indices. The method now
fails fast with clear error messages, improving defensive correctness.
I also added an early-return guard in subset() when size == 0 to make the
control flow clearer and easier to reason about. Additionally, the class
documentation now clarifies that ULongArray is not thread-safe due to its
mutable internal state.
These updates do not change behavior for valid inputs and require no
additional dependencies. The goal is to strengthen robustness and improve
long-term maintainability.
Type of change
Checklist before requesting a review