Skip to content

fix(core): replace unsafe Optional.get() calls with orElseThrow - #1809

Open
Rajkumar7633 wants to merge 1 commit into
google:mainfrom
Rajkumar7633:fix/unsafe-optional-get
Open

Rajkumar7633 wants to merge 1 commit into
google:mainfrom
Rajkumar7633:fix/unsafe-optional-get

Conversation

@Rajkumar7633

Copy link
Copy Markdown

Description

Replaces unsafe Optional.get() calls in the LLM flow request processors with orElseThrow() and meaningful error messages. Previously, a missing value would surface as an opaque NoSuchElementException; now it throws IllegalStateException with context about which value was expected.

This was split out of #1386 per review feedback, since it changes core behavior and is unrelated to the code assistant tutorial.

Changes

  • Basic.java: model name resolution now uses map/orElseGet/orElseThrow instead of isPresent()/get()
  • OutputSchema.java: outputSchema() accessed via orElseThrow with a descriptive message
  • RequestConfirmationLlmRequestProcessor.java: confirmationResult and function call IDs accessed via orElseThrow instead of get()

Testing

  • ./mvnw test -pl core -Dtest='BasicTest,OutputSchemaTest,RequestConfirmationLlmRequestProcessorTest' — all 50 tests pass

@google-cla

google-cla Bot commented Nov 13, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Replace Optional.get() calls in LLM flow request processors with
orElseThrow() and meaningful error messages, so missing values
surface as IllegalStateException with context instead of an
opaque NoSuchElementException.
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