apache / apache/netbeans

Introduce New Method refactoring with yield statement leads to broken code

Open
#8,278 0 comments 0 reactions 0 assignees View on GitHub
hints Java kind:bug
Dominant language
Java
Stars
3.1k
Forks
935
Avg merge
2d 3h
Merged PRs (30d)
17

Description

### Apache NetBeans version

Apache NetBeans 24

### What happened

Select piece of code with `yield` statement

![Image](https://github.com/user-attachments/assets/b9ea6965-a9b1-418b-98e8-a827ac100480)

and choose "Introduce Method" refactoring.

The generated code is broken. The new method
- has `void` return type
- continues to use `yield` instead of `return`

Looks like special treatment of `yield` is needed when introducing methods. CCing @jlahoda, @lahodaj

### Language / Project Type / NetBeans Component

_No response_

### How to reproduce

Select piece of code with `yield` statement

![Image](https://github.com/user-attachments/assets/b9ea6965-a9b1-418b-98e8-a827ac100480)

and choose "Introduce Method" refactoring.

### Did this work correctly in an earlier version?

No / Don't know

### Operating System

Any

### JDK

JDK21

### Apache NetBeans packaging

Own source build

### Anything else

_No response_

### Are you willing to submit a pull request?

No

Contributor guide

Open the contributing guide

Research direction

Reproduce this in Apache NetBeans 24 on JDK 21 by selecting code containing a yield statement and choosing Introduce Method. Inspect the generated method and its return behavior; done means the refactoring no longer produces a void method that still uses yield, and the resulting code is valid.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.