apache / apache/netbeans

Move Inner to Outer Level refactoring doesn't handle nested records

Open
#6,139 1 comment 1 reaction 0 assignees View on GitHub
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 18

### What happened

I had an inner class that I wanted to move to it's own top-level class. It in turn had some nested classes. Something like this:
```
private class MyClassA {
private static record IdAndPrefex(String id, String prefix) {}

private static class Request {
// more fields and methods
}

// various fields and methods
}
```
After moving to the outter level (with warnings about some fields that would not be accissible - I would fix that later) the result was this:
```
private class MyClassA {
private static class IdAndPrefex {
}

private static class Request {
// more fields and methods
}

// various fields and methods
}
```
The record was converted as a static class and the fields were lost.

### How to reproduce

Start with:
```
import java.util.Collection;
import java.util.List;

public class BugTest {

class Inner {
private static record NumberAndLetter(int number, String letter) {}
private Collection things = List.of(new NumberAndLetter(1, "a"),new NumberAndLetter(2, "b"));
public void doStuff() {
things.forEach(System.out::println);
}
}
}
```
Refactor to move ```Inner``` to an outer level.
The result is:
```
class Inner {

private final BugTest outer;

Inner(final BugTest outer) {
this.outer = outer;
}
private static class NumberAndLetter {
}
private Collection things = List.of(new NumberAndLetter(1, "a"), new NumberAndLetter(2, "b"));

public void doStuff() {
things.forEach(System.out::println);
}
}
```

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

No / Don't know

### Operating System

Ubuntu 22.04

### JDK

17.0.7

### Apache NetBeans packaging

Apache NetBeans provided installer

### Anything else

_No response_

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

No

Contributor guide

Open the contributing guide

Research direction

Start with the supplied BugTest reproduction and run the Move Inner to Outer Level refactoring on Inner. Trace the refactoring entry point and its handling of nested records; it is done when NumberAndLetter remains a record with its components and the resulting code preserves the shown collection and usage.

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.