Skip to content

Fixes #5553 : Skip UnnecessaryOptionalGet when lambda parameter is unnamed#5649

Closed
mirkoalicastro wants to merge 4 commits intogoogle:masterfrom
mirkoalicastro:mirkoalicastro/fix-unnecessary-optional-get-unnamed-variable
Closed

Fixes #5553 : Skip UnnecessaryOptionalGet when lambda parameter is unnamed#5649
mirkoalicastro wants to merge 4 commits intogoogle:masterfrom
mirkoalicastro:mirkoalicastro/fix-unnecessary-optional-get-unnamed-variable

Conversation

@mirkoalicastro
Copy link
Copy Markdown
Contributor

UnnecessaryOptionalGet suggested replacing .get() with the lambda parameter name, but the parameter _ (unnamed variable, Java 22+) produces uncompilable code since _ cannot be referenced.

Changes:

  • Added an early return when the lambda parameter source is _
  • Added a test guarded by assume().that(Runtime.version().feature()).isAtLeast(22)

Fixes #5553

@mirkoalicastro
Copy link
Copy Markdown
Contributor Author

Hi @cushon . Any chance you could have a look at this MR? 🙏

@mirkoalicastro mirkoalicastro requested a review from cushon April 10, 2026 14:12
@mirkoalicastro
Copy link
Copy Markdown
Contributor Author

Hey @cushon . I've made the requested changes. I'll leave the threads for you to resolve if everything looks good 🙏

copybara-service bot pushed a commit that referenced this pull request Apr 10, 2026
…named

`UnnecessaryOptionalGet` suggested replacing `.get()` with the lambda parameter name, but the parameter `_` (unnamed variable, Java 22+) produces uncompilable code since `_` cannot be referenced.

Changes:
- Added an early return when the lambda parameter source is `_`
- Added a test guarded by `assume().that(Runtime.version().feature()).isAtLeast(22)`

Fixes #5553

Fixes #5649

FUTURE_COPYBARA_INTEGRATE_REVIEW=#5649 from mirkoalicastro:mirkoalicastro/fix-unnecessary-optional-get-unnamed-variable bdcd042
PiperOrigin-RevId: 897687911
copybara-service bot pushed a commit that referenced this pull request Apr 10, 2026
…named

`UnnecessaryOptionalGet` suggested replacing `.get()` with the lambda parameter name, but the parameter `_` (unnamed variable, Java 22+) produces uncompilable code since `_` cannot be referenced.

Changes:
- Added an early return when the lambda parameter source is `_`
- Added a test guarded by `assume().that(Runtime.version().feature()).isAtLeast(22)`

Fixes #5553

Fixes #5649

FUTURE_COPYBARA_INTEGRATE_REVIEW=#5649 from mirkoalicastro:mirkoalicastro/fix-unnecessary-optional-get-unnamed-variable bdcd042
PiperOrigin-RevId: 897687291
copybara-service bot pushed a commit that referenced this pull request Apr 13, 2026
…named

`UnnecessaryOptionalGet` suggested replacing `.get()` with the lambda parameter name, but the parameter `_` (unnamed variable, Java 22+) produces uncompilable code since `_` cannot be referenced.

Changes:
- Added an early return when the lambda parameter source is `_`
- Added a test guarded by `assume().that(Runtime.version().feature()).isAtLeast(22)`

Fixes #5553

Fixes #5649

FUTURE_COPYBARA_INTEGRATE_REVIEW=#5649 from mirkoalicastro:mirkoalicastro/fix-unnecessary-optional-get-unnamed-variable bdcd042
PiperOrigin-RevId: 897687911
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.

Improved suggestions when unnamed variables are used

2 participants