Skip to content

Inline Method drops the qualifier of a method reference, changing program output #9774

Open

Description

@LingerMind

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

InlineMethod_S005_T07.java

  1. 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).
  2. Put the caret on getValue in the method reference getArrayHolder()::getValue.
  3. Refactor-> Inline ,and accept the defaults.
  4. 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: 99

After 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: 1

Did 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:

  1. Evaluate the qualifier once into a temporary and inline the body against it, e.g.
    ArrayHolder tmp = getArrayHolder();
    IntSupplier supplier = () -> { return tmp.getValue(); };
  2. Or refuse/warn when the qualifier is not a simple effectively-final variable.
  3. 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

Activity

  1. added
    Java[ci] enable extra Java tests (java.completion, java.source.base, java.hints, refactoring.java, form)
    on Nov 1, 2026
  2. adarshomrey commented on Nov 2, 2026

    @adarshomrey

    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.

  3. LingerMind commented on Nov 2, 2026

    @LingerMind
    Author

    3. 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.

    Hi,
    No one is currently working on this issue as far as I know, so feel free to take it.
    Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Java[ci] enable extra Java tests (java.completion, java.source.base, java.hints, refactoring.java, form)hintskind:bugBug report or fixneeds:triageRequires attention from one of the committers

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions