Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
swpalmer-cl opened this issue Jun 28, 2023 · 1 comment
Open
Labels
Java [ci] enable extra Java tests (java.completion, java.source.base, java.hints, refactoring.java, form) kind:bug Bug report or fix

Comments

@swpalmer-cl
Copy link

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<NumberAndLetter> 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<NumberAndLetter> 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

@swpalmer-cl swpalmer-cl added kind:bug Bug report or fix needs:triage Requires attention from one of the committers labels Jun 28, 2023
@mbien mbien added Java [ci] enable extra Java tests (java.completion, java.source.base, java.hints, refactoring.java, form) and removed needs:triage Requires attention from one of the committers labels Jun 29, 2023
@homberghp
Copy link
Contributor

Has followup in #7044.

See #7044 for additional findings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Java [ci] enable extra Java tests (java.completion, java.source.base, java.hints, refactoring.java, form) kind:bug Bug report or fix
Projects
None yet
Development

No branches or pull requests

3 participants