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#6681renechoi wants to merge 1 commit intospring-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
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
…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
force-pushed
the
fix/issue-6665-gemma-maas-missing-modelversion
branch
from
July 26, 2026 03:10
aab8c96 to
a3d8c81
Compare
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.
Resolves #6665.
Description
GoogleGenAiChatModelcurrently throwsNoSuchElementExceptionwhen calling.get()on themodelVersionfield inGenerateContentResponseif the model does not include it (e.g. Vertex Gemma MaaS models).This PR guards against
NoSuchElementExceptionby 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
GoogleGenAiChatModel.internalCall()to usegenerateContentResponse.modelVersion().orElse(geminiRequest.modelName()).GoogleGenAiChatModel.internalStream()to useresponse.modelVersion().orElse(request.modelName()).testResponseWithoutModelVersion()toGoogleGenAiChatModelExtendedUsageTestssimulating the Gemma MaaS response payload.