Skip to content

fix: Safely handle empty model in GoogleSearchTool request processor#1286

Merged
copybara-service[bot] merged 1 commit into
google:mainfrom
hemasekhar-p:googlesearch-tool-issue-fix
Jun 30, 2026
Merged

fix: Safely handle empty model in GoogleSearchTool request processor#1286
copybara-service[bot] merged 1 commit into
google:mainfrom
hemasekhar-p:googlesearch-tool-issue-fix

Conversation

@hemasekhar-p

Copy link
Copy Markdown
Contributor

1. Link to an existing issue (if applicable):

Problem:
GoogleSearchTool.processLlmRequest uses an unguarded Optional.get() to extract the model llmRequestBuilder.build().model().get(). If the model is absent, this throws a NoSuchElementException,

Solution:
Replaced the .get() call with .orElse(null) in GoogleSearchTool.java. By defaulting to null, the method's existing error-handling logic takes over and gracefully returning a Completable.error(IllegalArgumentException) and ensuring errors flow correctly through the Completable stream.

Testing Plan

Unit Tests:

  • I have added or updated unit tests for my change.
  • All unit tests pass locally.

Added testProcessLlmRequest_WithNoModel_DoesNotThrowsException to BaseToolTest.java. The test utilizes assertDoesNotThrow to verify that invoking processLlmRequest with a null model no longer triggers a NoSuchElementException. All tests in BaseToolTest pass successfully locally.

Checklist

  • I have read the CONTRIBUTING.md document.
  • My pull request contains a single commit.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes.
  • I have manually tested my changes end-to-end.
  • Any dependent changes have been merged and published in downstream modules.

@hemasekhar-p

Copy link
Copy Markdown
Contributor Author

@anFatum, Could you please review this PR.

@hemasekhar-p hemasekhar-p force-pushed the googlesearch-tool-issue-fix branch from 93c8d6e to 3fc9f6c Compare June 29, 2026 09:18
Comment thread core/src/test/java/com/google/adk/tools/BaseToolTest.java Outdated
@hemasekhar-p hemasekhar-p force-pushed the googlesearch-tool-issue-fix branch 2 times, most recently from de43368 to 6e79ecc Compare June 30, 2026 07:12
@hemasekhar-p hemasekhar-p force-pushed the googlesearch-tool-issue-fix branch from 6e79ecc to e255192 Compare June 30, 2026 08:36
@copybara-service copybara-service Bot merged commit ce6af87 into google:main Jun 30, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] GoogleSearchTool.processLlmRequest throws NoSuchElementException synchronously on an empty model

2 participants