fix: prevent NPE when array contains null elements in SentinelLinearSearch#1
Open
fix: prevent NPE when array contains null elements in SentinelLinearSearch#1
Conversation
…ms#7346) * feat: implement Tarjan's Bridge-Finding Algorithm Adds a classic graph algorithm to find bridge edges in an undirected graph in O(V + E) time. * style: format 2D arrays in TarjanBridgesTest --------- Co-authored-by: Deniz Altunkapan <deniz.altunkapan@outlook.com>
….0 (TheAlgorithms#7352) Bumps [com.puppycrawl.tools:checkstyle](https://github.com/checkstyle/checkstyle) from 13.3.0 to 13.4.0. - [Release notes](https://github.com/checkstyle/checkstyle/releases) - [Commits](checkstyle/checkstyle@checkstyle-13.3.0...checkstyle-13.4.0) --- updated-dependencies: - dependency-name: com.puppycrawl.tools:checkstyle dependency-version: 13.4.0 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
…4.9.8.2 to 4.9.8.3 (TheAlgorithms#7353) chore(deps-dev): bump com.github.spotbugs:spotbugs-maven-plugin Bumps [com.github.spotbugs:spotbugs-maven-plugin](https://github.com/spotbugs/spotbugs-maven-plugin) from 4.9.8.2 to 4.9.8.3. - [Release notes](https://github.com/spotbugs/spotbugs-maven-plugin/releases) - [Commits](spotbugs/spotbugs-maven-plugin@spotbugs-maven-plugin-4.9.8.2...spotbugs-maven-plugin-4.9.8.3) --- updated-dependencies: - dependency-name: com.github.spotbugs:spotbugs-maven-plugin dependency-version: 4.9.8.3 dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
TheAlgorithms#7354) Issue: TheAlgorithms#7349 Added: - Step-by-step algorithm explanation - Worked example with input/output - Time and space complexity analysis - Notes on when to use Jump Search vs Binary/Linear Search - @see references to related search algorithms
…#7326) * Correlation function for discrete variable correlation * Add unit tests for Correlation class Added unit tests for the Correlation class to validate correlation calculations under various scenarios, including linear dependence and constant values. * Added missing bracket * Refactor variable initialization in correlation method * Remove unused imports and clean up CorrelationTest * Fix formatting of variable declarations in correlation method * Update Correlation.java * Fix formatting in CorrelationTest.java * Enhance comments in correlation function Added detailed comments to the correlation function for better understanding. * Add correlation tests for various scenarios * Format comments for clarity in correlation method * Fix formatting and comments in correlation method
…ms#7356) (TheAlgorithms#7357) fix(BinarySearch): add null key check to prevent NPE Issue TheAlgorithms#7356: Add null check for the search value to prevent potential NullPointerException.
…ithms#7358) * Use BigInteger to prevent overflow in factorial calculation * chore: remove unnecessary comment * update * Fix: improve factorial implementation and formatting * test: final fix for FactorialTest logic and formatting * chore: final formatting and test fix for BigInteger * chore: final formatting and test fix for BigInteger
When searching for a non-null key in an array that contains null elements, the sentinel linear search would throw a NullPointerException because it called array[i].compareTo(key) without checking if array[i] is null. Added null check for array[i] in the while loop condition to prevent NPE and return the correct index when array elements themselves are null. Issue: TheAlgorithms#7318 (related)
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.
Fix: Prevent NPE when array contains null elements
Problem
When searching for a non-null key in an array that contains null elements, the sentinel linear search throws a
NullPointerExceptionbecause it callsarray[i].compareTo(key)without checking ifarray[i]is null.Solution
Added a null check for
array[i]in the while loop condition:Testing
Closes TheAlgorithms#7318 (related)