Skip to content

fix(searches): add null safety and empty matrix handling to RowColumnWiseSorted2dArrayBinarySearch - #7725

Open
hardikkaurani wants to merge 1 commit into
TheAlgorithms:masterfrom
hardikkaurani:fix/row-col-sorted-2d-array-null-safety
Open

hardikkaurani wants to merge 1 commit into
TheAlgorithms:masterfrom
hardikkaurani:fix/row-col-sorted-2d-array-null-safety

Conversation

@hardikkaurani

Copy link
Copy Markdown
Contributor
  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized it.
  • All filenames are in PascalCase.
  • All functions and variable names follow Java naming conventions.
  • All new algorithms have a URL in their comments that points to Wikipedia or other similar explanations.
  • All new algorithms include a corresponding test class that validates their functionality.
  • All new code is formatted with clang-format -i --style=file path/to/your/file.java

Description

This pull request adds null safety, empty matrix handling, and marks RowColumnWiseSorted2dArrayBinarySearch final:

  1. Null and Empty Input Validation: Added guards against matrix == null, empty 2D array (matrix.length == 0), empty first row (matrix[0].length == 0), and target == null, returning {-1, -1} safely.
  2. Jagged/Null Row Safety: Inside the pointer iteration loop, verified that each row is non-null and that colPointer < matrix[rowPointer].length before reading elements to prevent NullPointerException and ArrayIndexOutOfBoundsException.
  3. Class Modifier: Marked public final class RowColumnWiseSorted2dArrayBinarySearch.
  4. Expanded Tests: Added unit tests covering null matrix, empty 2D array, matrix with empty first row, null target, matrix containing a null row, and verifying the find() interface method.

Copilot AI balanced review requested due to automatic review settings November 2, 2026 06:04

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@hardikkaurani

hardikkaurani commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor Author

Hi @DenizAltunkapan,

Could you please review this pull request when you have a moment?

Summary of Changes

  • Null and Empty Input Handling: Added null and empty boundary checks in RowColumnWiseSorted2dArrayBinarySearch.search() to safely return {-1, -1} for null or empty inputs.
  • Ragged Array Safety: Added guards against null or shorter rows during pointer traversal in search() to prevent invalid index access.
  • Class Visibility: Declared RowColumnWiseSorted2dArrayBinarySearch as public final.
  • Test Coverage: Added unit tests covering null inputs, empty matrices, jagged arrays, and interface validation.

Test Results

  • RowColumnWiseSorted2dArrayBinarySearchTest: 25 passed, 0 failed, 0 skipped (BUILD SUCCESS).
  • Formatted the changes using clang-format in accordance with project conventions.

Thank you for your time and consideration!

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 66.66667% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.22%. Comparing base (8b49bc5) to head (e638b42).

Files with missing lines Patch % Lines
...arches/RowColumnWiseSorted2dArrayBinarySearch.java 66.66% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #7725      +/-   ##
============================================
- Coverage     82.23%   82.22%   -0.01%     
- Complexity     8402     8409       +7     
============================================
  Files           843      843              
  Lines         26140    26145       +5     
  Branches       5100     5101       +1     
============================================
+ Hits          21495    21498       +3     
+ Misses         3853     3852       -1     
- Partials        792      795       +3     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

3 participants