This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 237497 - Extract method: Generates uncompileable code when there are return values
Summary: Extract method: Generates uncompileable code when there are return values
Status: RESOLVED FIXED
Alias: None
Product: java
Classification: Unclassified
Component: Hints (show other bugs)
Version: 7.4
Hardware: PC Windows 7
: P2 normal (vote)
Assignee: Svata Dedic
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-10-22 20:33 UTC by markiewb
Modified: 2013-11-24 02:19 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
Shows the issue (85.72 KB, image/png)
2013-10-22 20:33 UTC, markiewb
Details
Simplified example (28.83 KB, image/png)
2013-10-22 20:34 UTC, markiewb
Details

Note You need to log in before you can comment on or make changes to this bug.
Description markiewb 2013-10-22 20:33:37 UTC
Created attachment 141429 [details]
Shows the issue

* Take this code
package javaapplication17;

public class JavaApplication17 {

    public static void main(String[] args) {
        new JavaApplication17().doit();
    }

    private String doit() {
        [if ("1".equals("2")) {
            return "";
        }
        return "bla";]
    }

    private String doit2() {
        if ("1".equals("2")) {
            return "";
        }
        return "bla";
    }

    private String doit3() {
        if ("1".equals("2")) {
            return "";
        }
        return "bla";
    }

}
* extract a method from the selected code (marked via []) 
* choose to refactor also other occurrences

ACTUAL: generated code cannot be compiled. The return value is not returned. See screenshot. For example

    private String doit2() {
        extractedMethod();
    }

EXPECTED: return values are supported too. No compile errors.

Product Version: NetBeans IDE 7.4 (Build 201310012201)
Java: 1.7.0_40; Java HotSpot(TM) 64-Bit Server VM 24.0-b56
Runtime: Java(TM) SE Runtime Environment 1.7.0_40-b43
System: Windows 7 version 6.1 running on amd64; Cp1252; en_US (nb)
User directory: C:\Users\markiewb\AppData\Roaming\NetBeans\7.4
Cache directory: C:\Users\markiewb\AppData\Local\NetBeans\Cache\7.4
Comment 1 markiewb 2013-10-22 20:34:20 UTC
Created attachment 141430 [details]
Simplified example

Here is another simplified example.
Comment 2 Jiri Prox 2013-10-22 20:37:19 UTC
reproducible
Comment 3 Svata Dedic 2013-10-30 12:58:33 UTC
The 'introduce hint' method computes the replacements in a wrong way; it carefully analyzes the selection and its surroundings to detect later usages of values computed within the selection. Such analysis is not done for the duplicates. The code should be rewritten to perform the analysis for each potential duplicate found. Also each of the duplicates may provide a different break/continue exit target, which does not seem to be handled properly now.
Comment 4 Svata Dedic 2013-11-22 17:02:28 UTC
Fixed in http://hg.netbeans.org/jet-main/rev/d4cbb394d97c
Comment 5 Quality Engineering 2013-11-24 02:19:49 UTC
Integrated into 'main-silver', will be available in build *201311240002* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)

Changeset: http://hg.netbeans.org/main-silver/rev/d4cbb394d97c
User: Svata Dedic <sdedic@netbeans.org>
Log: #235783, #237497: fixed behaviour if extracted method's outcome is further used. Refactored, code reused, de-optimized to make more readable