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.
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
Created attachment 141430 [details] Simplified example Here is another simplified example.
reproducible
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.
Fixed in http://hg.netbeans.org/jet-main/rev/d4cbb394d97c
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