Skip to content

fix(searches): add null safety and make ExponentialSearch public - #7651

Merged
alxkm merged 2 commits into
TheAlgorithms:masterfrom
hardikkaurani:fix/exponential-search-null-safety
Oct 21, 2026
Merged

alxkm merged 2 commits into
TheAlgorithms:masterfrom
hardikkaurani:fix/exponential-search-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 addresses accessibility, null safety, and consistency in ExponentialSearch:

  1. Public and Final Class Access: ExponentialSearch was package-private, preventing instantiation or usage by callers outside com.thealgorithms.searches. Marked the class public final class ExponentialSearch implements SearchAlgorithm consistent with other search algorithms in this package.
  2. Null and Empty Input Safety: Added guard against null array, empty array, and null key returning -1 instead of throwing NullPointerException.
  3. Comparable Contract Consistency: Replaced array[0].equals(key) and array[array.length - 1].equals(key) with key.compareTo(...) == 0 for proper Comparable semantics.
  4. Expanded Test Suite: Added tests for null array, null key, single-element array with absent target, duplicate elements, and string arrays.

Copilot AI balanced review requested due to automatic review settings October 21, 2026 16:03

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 reached their quota limit.

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

Copy link
Copy Markdown
Contributor Author

@alxkm Hi! I have submitted this PR to add null and empty array safety to ExponentialSearch, make the class public and final for external library callers, use consistent Comparable equality, and expand the test suite. Please review when you have a moment. Thanks!

@codecov-commenter

codecov-commenter commented Oct 21, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.18%. Comparing base (18c99d9) to head (447533a).

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #7651      +/-   ##
============================================
- Coverage     82.19%   82.18%   -0.01%     
  Complexity     8379     8379              
============================================
  Files           842      842              
  Lines         26101    26101              
  Branches       5090     5090              
============================================
- Hits          21454    21452       -2     
  Misses         3858     3858              
- Partials        789      791       +2     

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

@alxkm alxkm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good. Nice that the edge checks now use compareTo. Thank you for the contribution.

@alxkm
alxkm merged commit 3c3f04e into TheAlgorithms:master Oct 21, 2026
7 checks passed
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.

4 participants