Bug 439807

Summary: [inline] Refactor 'inline method' ignores assignment
Product: [Eclipse Project] JDT Reporter: Mike Gebirge <MikeGebirge>
Component: UIAssignee: JDT-UI-Inbox <jdt-ui-inbox>
Status: ASSIGNED --- QA Contact:
Severity: normal    
Priority: P3 CC: daniel_megert, manju656
Version: 3.8   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard: stalebug

Description Mike Gebirge CLA 2014-07-17 10:19:22 EDT
Example input:
public void parse(BufferedReader in) throws IOException {
    String word;
    while (!emptyLine(word = in.readLine())) {
        System.out.println(word);
    }
}
private static boolean emptyLine(String s) {
    return s.isEmpty();
}

Focus call to emptyLine() within parse()
Choose Refactor > Inline Method

Expected result:
public void parse(BufferedReader in) {
	String word;
    while (!(word = in.readLine()).isEmpty()) {
		System.out.println(word);
	}
}

Actual result:
public void parse(BufferedReader in) throws IOException {
    String word;
    String s = word = in.readLine();
    while (!s.isEmpty()) {
        System.out.println(word);
    }
}

Just for clarity: Input and Expected will read and output each line, 
then return normally. Actual result will go into an infinite loop if 
there's any input.

Admittedly, a 'for' loop is probably more appropriate here, but seeing 
that "Inline Method" can be used to replace ALL calls, this may 
introduce hard-to-find bugs as it changes the behaviour.

This is *not* a duplicate of #24931

The description link for the "UI" and "text" components are broken (that is, still pointing to http://www.eclipse.org/jdt/ui/index.html but should be pointing to blah/index.php -- the extensions differ). Should I open another bug?

Versions:
Version: Luna Release (4.4.0)
Build id: 20140612-0600
Eclipse IDE for Java Developers	4.4.0.20140612-0500
Eclipse Java Development Tools	3.10.0.v20140606-1536
Comment 1 Mike Gebirge CLA 2014-07-17 10:30:18 EDT
Actually, only now I realize that it says "s = word = in.readLine();", thereby only declaring an unnecessary variable. So yes, this *does* reopen https://bugs.eclipse.org/bugs/show_bug.cgi?id=24931.

As I can't re-open the old one, please let this stay open.
Comment 2 Eclipse Genie CLA 2018-11-26 10:30:44 EST
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.
Comment 3 Dani Megert CLA 2018-11-26 13:16:23 EST
Still an issue using R4.9.
Comment 4 Eclipse Genie CLA 2020-11-16 11:24:54 EST
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.
Comment 5 Eclipse Genie CLA 2022-12-16 15:29:45 EST
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.