LingerMind opened a new issue, #9769:
URL: https://github.com/apache/netbeans/issues/9769
### Apache NetBeans version
Apache NetBeans 31
### What happened
Inline Method removes the method declaration even though the same method is
still looked up by name via reflection. The refactored program compiles, but
fails at runtime with NoSuchMethodException.
Reproduced with Apache NetBeans 31, JDK 24.0.2, Windows 11.
Actual result after Refactor > Inline on compute():
public int compute() { // declaration removed
return 7;
}
int value = compute(); // replaced with: int value = 7;
The refactoring completes without any warning. Running the class then prints:
Value: 7
Exception in thread "main" java.lang.NoSuchMethodException:
InlineMethodReflectionRepro.compute()
at java.base/java.lang.Class.getMethod(Class.java:...)
at InlineMethodReflectionRepro.run(InlineMethodReflectionRepro.java:...)
Expected: either keep the declaration (it is still reachable via
reflection), or refuse/warn that the method is referenced by reflection. A
successful refactoring should not produce a program that throws at runtime.
### Language / Project Type / NetBeans Component
Java SE application (plain Java, no Maven/Gradle) — Java Refactoring /
Inline Method
### How to reproduce
1. Create a Java SE project with the class below.
2. Put the caret on the compute() call inside run().
3. Refactor > Inline... and accept the defaults.
4. Run the class.
//InlineMethod_S004_T02 is the test-case ID from my refactoring comparison
suite; the class itself is a self-contained reproducer.
import java.lang.reflect.Method;
public class InlineMethod_S004_T02 {
public int compute() {
return 7;
}
public void run() throws Exception {
// Refactoring operation: Inline Method
// Target location: invocation of compute() below
int value = compute();
System.out.println("Value: " + value);
Method m = InlineMethod_S004_T02.class.getMethod("compute");
System.out.println("Method: " + m.getName());
}
public static void main(String[] args) throws Exception {
new InlineMethod_S004_T02().run();
}
}
Compilation succeeds after inlining, but at runtime the second println never
executes and NoSuchMethodException is thrown. Repeatable every time.
### Did this work correctly in an earlier version?
No / Don't know
### Operating System
Windows 11 , 64-bit
### JDK
JDK 24.0.2, 64-bit
### Apache NetBeans packaging
Apache NetBeans binary zip
### Anything else
Deterministic; reproduced on every run.
The method is public, so deleting it also breaks binary compatibility for
external callers.
The reflective target is a string literal two lines below the inlined
call, so a conservative check (string literals passed to
getMethod/getDeclaredMethod) could catch this case. If full detection is out of
scope, a warning before deleting the declaration would already help.
I can attach the full project or a screen recording if needed.
### 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