Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

fix: GoogleGenAiChatModel throws NoSuchElementException on Vertex Gemma MaaS#6681

Open
renechoi wants to merge 1 commit into
spring-projects:mainspring-projects/spring-ai:mainfrom
renechoi:fix/issue-6665-gemma-maas-missing-modelversionrenechoi/spring-ai:fix/issue-6665-gemma-maas-missing-modelversionCopy head branch name to clipboard
Open

fix: GoogleGenAiChatModel throws NoSuchElementException on Vertex Gemma MaaS#6681
renechoi wants to merge 1 commit into
spring-projects:mainspring-projects/spring-ai:mainfrom
renechoi:fix/issue-6665-gemma-maas-missing-modelversionrenechoi/spring-ai:fix/issue-6665-gemma-maas-missing-modelversionCopy head branch name to clipboard

Conversation

@renechoi

Copy link
Copy Markdown

Resolves #6665.

Description
GoogleGenAiChatModel currently throws NoSuchElementException when calling .get() on the modelVersion field in GenerateContentResponse if the model does not include it (e.g. Vertex Gemma MaaS models).

This PR guards against NoSuchElementException by replacing the unguarded .get() with .orElse(request.modelName()) so that the metadata parsing gracefully falls back to the requested model name (or remains valid) instead of terminating a successful model generation call with an exception.

Changes

  • Updated GoogleGenAiChatModel.internalCall() to use generateContentResponse.modelVersion().orElse(geminiRequest.modelName()).
  • Updated GoogleGenAiChatModel.internalStream() to use response.modelVersion().orElse(request.modelName()).
  • Added testResponseWithoutModelVersion() to GoogleGenAiChatModelExtendedUsageTests simulating the Gemma MaaS response payload.

…ma MaaS

Vertex Gemma MaaS models omit the modelVersion field in GenerateContentResponse, causing an unguarded Optional.get() to throw NoSuchElementException. This commit uses orElse(request.modelName()) as a fallback to prevent NPEs and ensure successful parsing of valid responses.

Fixes spring-projects#6665

Signed-off-by: renechoi <renechoi90@gmail.com>
@renechoi
renechoi force-pushed the fix/issue-6665-gemma-maas-missing-modelversion branch from aab8c96 to a3d8c81 Compare July 26, 2026 03:10
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.

GoogleGenAiChatModel throws NoSuchElementException for models that omit modelVersion in GenerateContentResponse (e.g. Vertex Gemma MaaS)

2 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.