Skip to content

fix: prevent ArrayIndexOutOfBoundsException in provider autocomplete search#2485

Open
D3V41 wants to merge 1 commit into
developfrom
fix/provider-autocomplete-index-out-of-bounds
Open

fix: prevent ArrayIndexOutOfBoundsException in provider autocomplete search#2485
D3V41 wants to merge 1 commit into
developfrom
fix/provider-autocomplete-index-out-of-bounds

Conversation

@D3V41

@D3V41 D3V41 commented Jun 25, 2026

Copy link
Copy Markdown
Collaborator

Problem

Typing a lastname followed by a comma (e.g. la,) in the provider autocomplete input throws ArrayIndexOutOfBoundsException: Index 1 out of bounds for length 1 at ProviderData.searchProvider().

searchStr.split(",") drops trailing empty strings, so "la," returns ["la"]. Accessing array[1] for the firstname then fails.

image

Fix

Use split(",", -1) so the trailing empty field is preserved (["la", ""]). The firstname becomes an empty string and the search runs normally. Also removed a redundant new String[2] allocation that was immediately overwritten.

Summary by Sourcery

Bug Fixes:

  • Handle trailing commas in provider search input without causing ArrayIndexOutOfBoundsException.

Summary by cubic

Prevent ArrayIndexOutOfBoundsException in provider autocomplete when a user types a lastname followed by a comma (e.g., "la,") by preserving the empty firstname during split. Also removes a redundant array allocation.

Written for commit 337d3ed. Summary will update on new commits.

Review in cubic

Summary by CodeRabbit

  • Bug Fixes
    • Improved provider search input handling when a comma-separated name includes a trailing empty value.
    • Prevented errors during search and made first-name/last-name trimming work correctly when only a last name is entered.

@D3V41 D3V41 self-assigned this Jun 25, 2026
@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@sourcery-ai

sourcery-ai Bot commented Jun 25, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adjusts provider autocomplete search string splitting to safely handle trailing commas and removes a redundant array allocation.

File-Level Changes

Change Details Files
Make provider autocomplete search robust to inputs with a trailing comma and simplify array handling.
  • Change the search string split call to use split(",", -1) so trailing empty fields are preserved and array indexing is safe.
  • Remove the unnecessary pre-allocation of a fixed-size String array that was immediately overwritten by the split result.
  • Document the reasoning for the new split behavior with inline comments explaining the preservation of trailing empty strings and avoidance of ArrayIndexOutOfBoundsException.
src/main/java/ca/openosp/openo/providers/data/ProviderData.java

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@github-actions

Copy link
Copy Markdown

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Snapshot Warnings

⚠️: No snapshots were found for the head SHA 337d3ed.
Ensure that dependencies are being submitted on PR branches and consider enabling retry-on-snapshot-warnings. See the documentation for more information and troubleshooting advice.

Scanned Files

None

@coderabbitai

coderabbitai Bot commented Jun 25, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 555c585b-0a53-4192-abe8-8f91b3ab38d1

📥 Commits

Reviewing files that changed from the base of the PR and between 5f49a01 and 337d3ed.

📒 Files selected for processing (1)
  • src/main/java/ca/openosp/openo/providers/data/ProviderData.java

📝 Walkthrough

Walkthrough

searchProvider now preserves trailing empty fields when splitting comma-separated search input, so lastname-only queries keep the empty firstname segment and avoid the previous array bounds failure.

Changes

Provider search parsing fix

Layer / File(s) Summary
Preserve trailing search segment
src/main/java/ca/openosp/openo/providers/data/ProviderData.java
searchProvider uses split(",", -1) to retain a trailing empty field when parsing search input, with comments noting the prior failure case.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~5 minutes

Poem

🐇 I hopped through commas, neat and spry,
The last name landed, no field left shy.
With split(..., -1) I grin and cheer,
No bounds to bite my carrot ear!
Hoppity hop, the search is clear.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: fixing the provider autocomplete crash caused by trailing comma input.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/provider-autocomplete-index-out-of-bounds

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request updates the searchProvider method in ProviderData.java to use split(",", -1) when parsing the search string. This ensures that trailing empty strings are preserved (e.g., when a user inputs 'lastname,'), preventing an ArrayIndexOutOfBoundsException when accessing the split array. There are no review comments, so I have no feedback to provide.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

@sourcery-ai sourcery-ai Bot 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.

Hey - I've left some high level feedback:

  • Consider defensively checking the length of the array before accessing index 1 to make the parsing more resilient to unexpected input formats (e.g., multiple commas or unusual whitespace).
  • The new comment block is a bit verbose; you could tighten it to a single concise sentence describing the use of split(",", -1) to preserve trailing empty tokens and avoid the exception.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider defensively checking the length of the `array` before accessing index 1 to make the parsing more resilient to unexpected input formats (e.g., multiple commas or unusual whitespace).
- The new comment block is a bit verbose; you could tighten it to a single concise sentence describing the use of `split(",", -1)` to preserve trailing empty tokens and avoid the exception.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@D3V41 D3V41 requested a review from LiamStanziani June 25, 2026 12:22

@cubic-dev-ai cubic-dev-ai Bot 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.

No issues found across 1 file

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Re-trigger cubic

@LiamStanziani LiamStanziani left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks good.

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.

2 participants