Repository navigation
Open
Labels
Java[ci] enable extra Java tests (java.completion, java.source.base, java.hints, refactoring.java, form)[ci] enable extra Java tests (java.completion, java.source.base, java.hints, refactoring.java, form)hintskind:bugBug report or fixBug report or fixneeds:triageRequires attention from one of the committersRequires attention from one of the committers
Description
Apache NetBeans version
Apache NetBeans 31
What happened
Inline Method on a bound method reference replaces the reference with a lambda and drops the qualifier expression entirely. In this case the qualifier is a method call with a side effect, so the refactored program produces a different result.
Language / Project Type / NetBeans Component
Java SE application
How to reproduce
- Create a Java SE project and add a file named InlineMethod_S005_T07.java with the
code below (InlineMethod_S005_T07 is the test-case ID from my refactoring
comparison suite; the class is self-contained). - Put the caret on getValue in the method reference getArrayHolder()::getValue.
- Refactor-> Inline ,and accept the defaults.
- Run the class.
Before reflactoring:
import java.util.function.IntSupplier;
public class InlineMethod_S005_T07 {
private static int[] values = new int[]{1, 2, 3};
static class ArrayHolder {
int getValue() {
return values[0];
}
}
static ArrayHolder getArrayHolder() {
values[0] = 99;
return new ArrayHolder();
}
static int run() {
IntSupplier supplier = getArrayHolder()::getValue;
return supplier.getAsInt();
}
public static void main(String[] args) {
System.out.println(run());
}
}
//output: 99After reflactoring:
import java.util.function.IntSupplier;
public class InlineMethod_S005_T07 {
private static int[] values = new int[]{1, 2, 3};
static class ArrayHolder {
}
static ArrayHolder getArrayHolder() {
values[0] = 99;
return new ArrayHolder();
}
static int run() {
IntSupplier supplier = () -> {
return values[0];
};
return supplier.getAsInt();
}
public static void main(String[] args) {
System.out.println(run());
}
}
//output: 1Did this work correctly in an earlier version?
Apache NetBeans 31
Operating System
Windows 11
JDK
JDK 24
Apache NetBeans packaging
Apache NetBeans binary zip
Anything else
Possible directions:
- Evaluate the qualifier once into a temporary and inline the body against it, e.g.
ArrayHolder tmp = getArrayHolder();
IntSupplier supplier = () -> { return tmp.getValue(); }; - Or refuse/warn when the qualifier is not a simple effectively-final variable.
- Keep the current path only for unbound references (Type::method).
The same code path is used for every bound method reference, so this is not specific to the test case. I can provide the full project or a screen recording if useful.
Are you willing to submit a pull request?
No
Metadata
Metadata
Assignees
Labels
Java[ci] enable extra Java tests (java.completion, java.source.base, java.hints, refactoring.java, form)[ci] enable extra Java tests (java.completion, java.source.base, java.hints, refactoring.java, form)hintskind:bugBug report or fixBug report or fixneeds:triageRequires attention from one of the committersRequires attention from one of the committers
Activity
adarshomrey commentedon Nov 2, 2026
Hi,
I'm interested in working on this issue as a contributor to Apache NetBeans. I'd like to investigate the inline method refactoring implementation, reproduce the issue, and work towards a fix.
If nobody is currently working on it, would it be possible for me to take this issue?
I'm happy to share my findings and submit a pull request once the fix is ready.
LingerMind commentedon Nov 2, 2026
Hi,
No one is currently working on this issue as far as I know, so feel free to take it.
Thanks!