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

   ### Apache NetBeans version
   
   Apache NetBeans 32
   
   ### What happened
   
   Inline Method on A.m(), whose body is a single super.toString() call, 
inlined into
   static B.test() emits super.toString() directly inside a static method of 
another
   type. The file no longer compiles, while the refactoring reports success 
with no
   warning.
   
   ### Language / Project Type / NetBeans Component
   
   Java SE application
   
   ### How to reproduce
   
   1. New Project > Java with Maven > Java Application (package 
com.mycompany.mavenproject5).
   2. Add the class below.
   3. Put the caret on m in  new A().m();  and choose Refactor > Inline...
   4. Build the project.
   
   
   ```java
   package com.mycompany.mavenproject5;
   
   // Refactoring operation: InlineMethod on new A().m() inside B.test()
   public class InlineMethod_S007_T01 {
   
       static class A {
           // Target method containing a super call
           void m() {
               super.toString();
           }
       }
   
       static class B {
           static void test() {
               // Invocation site to be inlined
               new A().m();
           }
       }
   
       public static void main(String[] args) {
           B.test();
           System.out.println("T01 done");
       }
   }
   ```
   
   **Actual result**
   
   ```java
   static class A {
   }
   
   static class B {
       static void test() {
           super.toString();
       }
   }
   ```
   ```text
   error: non-static variable super cannot be referenced from a static context
           super.toString();
           ^
   ```
   
   [T01.java](https://github.com/user-attachments/files/35278321/T01.java)
   
   ### 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
   
   Suggested fix: before rewriting, scan the method body for `super`. If any 
`super`
   occurrence exists and the target context is not the declaring class itself, 
refuse with
   a message such as:
   ```text
   Cannot inline a super invocation into a method of a different type.
   ```
   
   ### 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