netbeans
netbeans copied to clipboard
Introducing method on "instanceof" caused compile error
Apache NetBeans version
Apache NetBeans 21
What happened
Using "introduce method" on "instanceof" caused compile error in output program.
Language / Project Type / NetBeans Component
Java Maven Project Java Application
How to reproduce
Input program:
class X {
private void foo(Object o) {
if (o instanceof X x) { // select the entire o instanceof X x
System.out.println(x.toString());
x.foo(null);
}
}
}
Steps: Select “o instanceof X x” Refactor -> Introduce -> Method
Actual output:
class X {
private void foo(Object o) {
if (extract1(o)) { // select the entire o instanceof X x
System.out.println(x.toString());
x.foo(null);
}
}
private boolean extract1(Object o) {
return o instanceof X x;
}
}
Expected result: Prevent from introducing method on "instanceof"
Did this work correctly in an earlier version?
No / Don't know
Operating System
Windows 11
JDK
22.0.1
Apache NetBeans packaging
Apache NetBeans provided installer
Anything else
No response
Are you willing to submit a pull request?
No