Skip to content

reject null input in longestCommonSubstringLengthArray - #774

Open
dxbjavid wants to merge 1 commit into
apache:masterfrom
dxbjavid:lcs-substring-array-null-check
Open

dxbjavid wants to merge 1 commit into
apache:masterfrom
dxbjavid:lcs-substring-array-null-check

Conversation

@dxbjavid

Copy link
Copy Markdown
Contributor

LongestCommonSubsequence.longestCommonSubstringLengthArray dereferences left and right straight away to size the DP array, so passing a null sequence throws a raw NullPointerException out of the public method. Its siblings apply, logestCommonSubsequence and longestCommonSubsequence all guard null and throw IllegalArgumentException, and that behaviour is part of their documented contract, so a caller that catches IllegalArgumentException as the class leads it to expect is instead surprised by an NPE from this one method. Add the same null check and document it so the method lines up with the rest of the class.

  • Read the contribution guidelines for this project.
  • Read the ASF Generative Tooling Guidance if you use Artificial Intelligence (AI).
  • I used AI to create any part of, or all of, this pull request. Which AI tool was used to create this pull request, and to what extent did it contribute? Claude Code (Anthropic) helped spot the inconsistency with the sibling methods and draft the guard and the regression tests; I reviewed the change and the test evidence.
  • Run a successful build using the default Maven goal with mvn; that's mvn on the command line by itself.
  • Write unit tests that match behavioral changes, where the tests fail if the changes to the runtime are not applied. This may not always be possible, but it is a best practice.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Each commit in the pull request should have a meaningful subject line and body. Note that a maintainer may squash commits during the merge process.

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.

1 participant