LingerMind opened a new issue, #9835:
URL: https://github.com/apache/netbeans/issues/9835

   ### Apache NetBeans version
   
   Apache NetBeans 32
   
   ### What happened
   
   x is declared private in A. Private fields are not inherited by Sub, so 
after inlining the simple name x does not resolve at the call site. A 
qualifying access such as ((A) this).x would compile, because A and Sub are 
nested in the same top-level class and private access is permitted within that 
body.
   
   ### Language / Project Type / NetBeans Component
   
   Java SE application
   
   ### How to reproduce
   
   1. Create a Java Maven project.
   2. Add a class `Project` with the following content.
   3. Place the caret on the m() call inside Sub.run().
   4. Refactor > Inline , accept the preview.
   
   Before refactoring:
   ```
   public class Project {
   
       static class A {
           private int x = 3;
   
           int m() {
               return x;
           }
       }
   
       static class Sub extends A {
           void run() {
               int v = m();
               System.out.println(v);
           }
       }
   
       public static void main(String[] args) {
           new Sub().run();
       }
   }
   //output: 3
   ```
   
   After refactoring:
   ```
   public class Project {
   
       static class A {
           private int x = 3;
   
           int m() {
               return x;
           }
       }
   
       static class Sub extends A {
           void run() {
               int v = x;            // <-- error: x has private access in A
               System.out.println(v);
           }
       }
   
       public static void main(String[] args) {
           new Sub().run();
       }
   }
   
   ```
   
   
   
   
   
   ### Did this work correctly in an earlier version?
   
   No / Don't know
   
   ### Operating System
   
   Windows 11
   
   ### JDK
   
   JDK 24
   
   ### Apache NetBeans packaging
   
   Apache NetBeans binary zip
   
   ### Anything else
   
   Expected
   One of:
   the refactoring is refused with a reason, e.g. Cannot inline: x has private 
access in A, or the inlined expression keeps the receiver type, e.g. int v = 
((A) this).x;
   
   ### Are you willing to submit a pull request?
   
   No


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to